Norman McEntire
Version 1.0 2009 Oct 2
Copyright © 2009 Servin Corporation. http://servin.com
These code samples show you the most frequently used ways that you can use UIApplication in your iPhone programs.
No matter where you are in your code, from any file, you can access your program's UIApplication object.
Option 1: Gain Access to UIApplication object:
UIApplication *application; application = [UIApplication sharedApplication]; // Get idleTimeDisabled property BOOL result; result = application.idleTimerDisabled;
Option 2: Gain Access to UIApplication Object and property in a single statement:
result = [UIApplication sharedApplication].idleTimerDisabled;
Option 3: Older coding method:
result = [[UIApplication sharedApplication] isIdleTimerDisabled];
When enabled, the idle timer puts your iPhone or iPod Touch into sleep mode after a given amount of non-use. Typically, this is want you want.
When disabled, the idle timer will not put your device to sleep. You sometimes want this, based on the type of iPhone application you are running.
Get current value:
BOOL result; result = [UIApplication sharedApplication].idleTimerDisabled;
Timer Disabled:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Timer Enabled:
[UIApplication sharedApplication].idleTimerDisabled = NO;
The status bar takes up 20 pixels at the very top of the screen, showing cell phone signal strength, network activity, time, and other info.
Get status:
BOOL result; result = [UIApplication sharedApplication].statusBarHidden;
Hide status bar:
[UIApplication sharedApplication].statusBarHidden = YES;
Show status bar:
[UIApplication sharedApplication].statusBarHidden = NO;
The network activity icon is a small icon on the status bar. You can check the status, hide it, or make it visible.
Check status:
BOOL result result = [UIApplication sharedApplication].networkActivityIndicatorVisible;
Hide:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
Show:
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
The icon on the home screen can show a number, or badge, on the icon.
Set the icon badge number:
[UIApplication sharedApplication].applicationIconBadgeNumber = 10;
Remove Icon Badge Number:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
From anywhere in your program, you can access the UIApplicationDelegate object. This is often useful to access that object's properties and/or methods.
DemoAppDelegate *appDelegate; appDelegate = [UIApplication sharedApplication].delegate;
Sometimes you wish to transfer control from your application to another application.
Dial the phone (your app ends and the phone dialer begins):
// Dial the phone NSString *phoneToCall = @"tel: 123-456-7890"; NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded]; [[UIApplication sharedApplication] openURL:url];
Transfer to a web page (your app ends and the web app begins):
// Access web page NSURL *url = [[NSURL alloc] initWithString:@"http://servin.com"]; [[UIApplication sharedApplication] openURL:url];
Updated 2009 Oct 2
Content viewable on all web browsers, including smart mobile phone devices.
Copyright © 1995-2009 Servin Corporation. All rights reserved.