Discussion Forums  >  iOS / Android Beta Testers

Replies: 14    Views: 167

chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
Fourm StarFourm StarFourm Star
06/24/13 12:37 AM (9 years ago)

iOS class methods

Thought I'd consolidate all the 'class methods' in the iOS buzztouch files for all who are interested. There's some really useful methods in here that often get overlooked. Using one is really easy. First, make sure the class name (listed above the respective listing of methods) is imported into your plugin screen (aka viewController). Then, call the method like so: [BT_class someMethod:someArgument]; --------------------------------------------------------- Class Methods BT_color +(UIColor *)getColorFromHexString:(NSString *)hexString; BT_dates +(NSString *)getLocalDateTime; +(int)getTimeElapsed:(NSString *)previousDateString interval:(NSString *)interval; BT_debugger +(void)showIt:(id)theCallingObject theMessage:(NSString *)theMessage; BT_fileManager +(NSString*)getFilePath:(NSString *)fileName; +(NSURL*)getFileURL:(NSString *)fileName; +(BOOL)markFileAsDoNotBackup:(NSString *)fileName; +(NSString*)getBundlePath:(NSString *)fileName; +(BOOL)doesLocalFileExist:(NSString *)fileName; +(BOOL)doesFileExistInBundle:(NSString *)fileName; +(BOOL)saveDataToFile:(NSData *)theData fileName:(NSString *)fileName; +(BOOL)saveImageToFile:(UIImage *)theImage fileName:(NSString *)fileName; +(void)deleteFile:(NSString *)fileName; +(void)deleteAllLocalData; +(void)deleteScreenData:(NSString *)theScreenId; +(BOOL)makeWritableFromBundle:(NSString *)fileName; +(BOOL)saveTextFileToCacheWithEncoding:(NSString *)stringData fileName:(NSString *)fileName encodingFlag:(int)encodingFlag; +(NSString *)readTextFileFromCacheWithEncoding:(NSString *)fileName encodingFlag:(int)encodingFlag; +(NSString *)readTextFileFromBundleWithEncoding:(NSString *)fileName encodingFlag:(int)encodingFlag; +(NSString *)getHumanReadableLocalStorageSize; +(int)getLocalDataSizeInt; +(int)countLocalFiles; +(NSString *)stringFromFileSize:(int)theSize; +(int)getSizeOfFile:(NSString *)path; +(int)getSizeOfFolder:(NSString*)folderPath; +(UIImage *)getImageFromFile:(NSString *)fileName; BT_httpEater +(BT_httpEaterResponse *)get:(id)url; +(BT_httpEaterResponse *)get:(id)url headerFields:(NSDictionary *)headerFields; +(BT_httpEaterResponse *)post:(id)url body:(NSData *)body; +(BT_httpEaterResponse *)post:(id)url body:(NSData *)body headerFields:(NSDictionary *)headerFields; +(BT_httpEaterResponse *)downloadURL:(NSURL *)url method:(NSString *)method body:(NSData *)body headerFields:(NSDictionary *)headerFields; +(NSString *)queryDictionaryToString:(NSDictionary *)query; +(NSURL *)urlWithProtocol:(NSString *)protocol host:(NSString *)host port:(int)port path:(NSString *)path query:(id)query; BT_imageTools +(UIImage *)makeRoundCornerImage:(UIImage*)img :(int) cornerWidth :(int) cornerHeight; +(NSString *)getWhiteIconName:(NSString *)theIconName; +(UIImage *)scaleToSize:(UIImage *)img theSize:(CGSize)theSize; +(UIImage *)scaleProportionalToSize:(UIImage *)img theSize:(CGSize)theSize; BT_reachability //reachabilityWithHostName- Use to check the reachability of a particular host name. + (Reachability*) reachabilityWithHostName: (NSString*) hostName; //reachabilityWithAddress- Use to check the reachability of a particular IP address. + (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress; //reachabilityForInternetConnection- checks whether the default route is available. // Should be used by applications that do not connect to a particular host + (Reachability*) reachabilityForInternetConnection; //reachabilityForLocalWiFi- checks whether a local wifi connection is available. + (Reachability*) reachabilityForLocalWiFi; BT_strings +(NSString *)getPrefString:(NSString *)nameOfPref; +(void)setPrefString:(NSString *)nameOfPref valueOfPref:(NSString *)valueOfPref; +(NSString *)replaceString:(NSString *)original findString:(NSString *)findString replaceWith:(NSString *)replaceWith; +(NSString *)mergeBTVariablesInString:(NSString *)theURL; +(NSString *)getJsonPropertyValue:(NSDictionary *)theValues nameOfProperty:(NSString *)nameOfProperty defaultValue:(NSString *)defaultValue; +(NSString *)getStyleValueForScreen:(BT_item *)theParentScreenData nameOfProperty:(NSString *)nameOfProperty defaultValue:(NSString *)defaultValue; +(NSString *)formatTimeFromSeconds:(NSString *)seconds; +(NSString *)dateGMTDateFromString:(NSString *)theGMTDateString; +(NSString *)cleanUpCharacterData:(NSString *)theString; +(NSString *)stripHTMLFromString:(NSString *)html; +(NSString *)getFileNameFromURL:(NSString *)theURLString; BT_database +(void)initDatabase:(NSString *)databaseName; BT_viewControllerManager //main navigation methods... +(id)initViewControllerForScreen:(BT_item *)theScreen; +(BT_item *)getErrorViewController; +(void)handleTapToLoadScreen:(BT_item *)parentScreenData theMenuItemData:(BT_item *)theMenuItemData theScreenData:(BT_item *)theScreenData; +(void)handleLeftButton:(BT_item *)parentScreenData; +(void)handleRightButton:(BT_item *)parentScreenData; +(void)closeChildApp; +(void)showParentApp; //special action methods that don't launch another view controller... +(void)placeCallWithScreenData:(BT_item *)theScreenData; +(void)sendEmailWithScreenData:(BT_item *)theScreenData imageAttachment:(UIImage *)imageAttachment imageAttachmentName:(NSString *)imageAttachmentName; +(void)sendEmailWithAttachmentFromScreenData:(BT_item *)theScreenData theAttachmentData:(NSData *)theAttachmentData attachmentName:(NSString *)attachmentName; +(void)sendEmailFromWebLink:(BT_item *)theScreenData toAddress:(NSString *)toAddress; +(void)sendTextMessageWithScreenData:(BT_item *)theScreenData; BT_viewUtilities +(CGRect)frameForNavBarAtOrientation:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(CGRect)frameForToolBarAtOrientation:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(CGRect)frameForAdView:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UIView *)getProgressView:(NSString *)loadingText; +(UIColor *)getTextColorForScreen:(BT_item *)theScreenData; +(UIColor *)getNavBarBackgroundColorForScreen:(BT_item *)theScreenData; +(void)configureBackgroundAndNavBar:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UITableView *)getTableViewForScreen:(BT_item *)theScreenData; +(UIToolbar *)getWebToolBarForScreen:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UIToolbar *)getMapToolBarForScreen:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UIToolbar *)getImageToolBarForScreen:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UIToolbar *)getAudioToolBarForScreen:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UIToolbar *)getQuizToolBarForScreen:(UIViewController *)theViewController theScreenData:(BT_item *)theScreenData; +(UISegmentedControl *)getButtonForQuiz:(UIViewController *)theViewController theFrame:(CGRect)theFrame theTag:(int)theTag buttonColor:(UIColor *)buttonColor; +(UILabel *)getLabelForQuizButton:(CGRect)theFrame fontSize:(int)fontSize fontColor:(UIColor *)fontColor; +(UIView *)getCellBackgroundForListRow:(BT_item *)theScreenData theIndexPath:(NSIndexPath *)theIndexPath numRows:(int)numRows; +(UIView *)applyRoundedCorners:(UIView *)theView radius:(int)radius; +(UITextView *)applyRoundedCornersToTextView:(UITextView *)theView radius:(int)radius; +(UIImageView *)applyRoundedCornersToImageView:(UIImageView *)theView radius:(int)radius; +(UIView *)applyBorder:(UIView *)theView borderWidth:(int)borderWidth borderColor:(UIColor *)borderColor; +(UIView *)applyDropShadow:(UIView *)theView shadowColor:(UIColor *)shadowColor; +(UIView *)applyGradient:(UIView *)theView colorTop:(UIColor *)colorTop colorBottom:(UIColor *)colorBottom; BT_device +(void)registerForPushNotifications:(NSString *)registerURL; +(void)unRegisterForPushNotifications:(NSString *)registerURL;
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
Fourm StarFourm StarFourm Star
like
06/24/13 12:42 AM (9 years ago)
So, for instance, let's say you have a UIImage object named "someImage" and you want to resize it to 100x100. Simply use the method out of BT_imageTools class: CGSize *newImageSize = CGSizeMake(100,100); UIImage *newImage = [BT_imageTools scaleToSize:someImage theSize:newImageSize];
 
Joe Sprott
Code is Art
Profile
Posts: 414
Reg: Aug 20, 2011
Melbourne, FL
10,290
Fourm StarFourm StarFourm Star
like
06/24/13 12:45 AM (9 years ago)
are you still interested in getting together sometime for a training Joe
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
Fourm StarFourm StarFourm Star
like
06/24/13 12:47 AM (9 years ago)
yeah- things have been kind of busy, but I think this week should be pretty flexible. How does Wednesday or Thursday look?
 
Joe Sprott
Code is Art
Profile
Posts: 414
Reg: Aug 20, 2011
Melbourne, FL
10,290
Fourm StarFourm StarFourm Star
like
06/24/13 12:53 AM (9 years ago)
thursday sounds perfect. how about a 1 hour session
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
Fourm StarFourm StarFourm Star
like
06/24/13 12:54 AM (9 years ago)
sounds good
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
06/24/13 12:55 AM (9 years ago)
I've got something similar. It's even more fun to make your own or create singleton classes. I've got a class dedicated to my crazy spewings mainly text and label completing ones. makes them ridiculous methods with bt_color and bt_strings a little nicer looking in your code.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
06/24/13 02:33 AM (9 years ago)
I was just about to mention bt_color for hex code colors (kittsy showed me this originally). GREAT post chris. David https://buzztouchmods.com
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
Fourm StarFourm StarFourm Star
like
06/24/13 04:17 AM (9 years ago)
Nice collection, Chris :) Cheers! -- Smug
 
Jake Chasan
Veteran developer
Profile
Posts: 1684
Reg: May 13, 2011
location unknow...
29,640
Fourm StarFourm StarFourm Star
like
06/24/13 07:53 AM (9 years ago)
Very nice list. Thanks for sharing. Jake
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
Fourm StarFourm StarFourm Star
like
06/24/13 11:13 AM (9 years ago)
Hi Chris, Indeed a nice list. Nice to have it all together. Thanks! Best Regards, Danny
 
Sheri
Code is Art
Profile
Posts: 1093
Reg: Sep 23, 2011
location unknow...
22,830
Fourm StarFourm StarFourm Star
like
06/24/13 11:49 AM (9 years ago)
Thanks for the collection Chris1 helps organize the brain which is much needed!
 
WebNevees
Code is Art
Profile
Posts: 206
Reg: Oct 28, 2012
KL
11,660
Fourm StarFourm StarFourm Star
like
06/24/13 12:04 PM (9 years ago)
Great post. Thanks Chris!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
Fourm StarFourm StarFourm Star
like
06/25/13 01:11 AM (9 years ago)
Yup...this is awesome. Now I know why I haven't explained each one of these in detail - sigh. One of the goals that haven't been met yet is to name the iOS and Android files and methods as closely as possible so they are nearly the same. A standard file naming and method naming convention would make things much easier - for all of us. The fact is, they can never be exactly the same but they should get closer than they are now. I've experiment with all sorts of documenter type software over the last few years and none of it works as I expect - which is why the BT docs (or no docs actually) suck so bad. Chris, this is an important first step to a great set of docs, thanks a bunch for the effort!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
Fourm StarFourm StarFourm Star
like
06/25/13 09:58 AM (9 years ago)
I agree nice post and perfectly organized! Chris and Kittsy should team up to do a webinar together for better explanation. Thanks a lot!
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.