Great UIKit/Objective-C code snippets

Keith Adler picture Keith Adler · Jun 10, 2010 · Viewed 9.9k times · Source

New to Objective-C iPhone/iPod touch/iPad development, but I'm starting to discover lots of power in one-liners of code such as this:

[UIApplication sharedApplication].applicationIconBadgeNumber = 10;

Which will display that distinctive red notification badge on your app iphone with the number 10.

Please share you favorite one or two-liners in Objective-C for the iPhone/iPod touch/iPad here. PUBLIC APIs ONLY.

Answer

RRUZ picture RRUZ · Jun 14, 2010

Open an URL in Safari

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/"]];

Hide the status bar

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

Dial a Phone Number (iPhone Only)

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://9662256888"]];

Launch the Apple Mail

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

stop responding to touch events

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

active the touch events

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

Show the network Activity Indicator

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

Hide the network Activity Indicator

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

Prevents iPhone goes into sleep mode

[UIApplication sharedApplication].idleTimerDisabled = YES;