Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
UIApplication: Difference between revisions - iPhone Development Wiki

UIApplication: Difference between revisions

From iPhone Development Wiki
(Created page with '{{occlass|library=UIKit.framework}} UIApplication is a singleton object that represents the application. == Parameters for UIKit applications == UIApplicationMain recogniz…')
 
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{occlass|library=UIKit.framework}}
[[UIApplication]] is a singleton object that represents the application.
 
== UIApp ==
{{function signature
|signature=extern UIApplication* UIApp;
|firmware=2.0 –
}}
The method {{ObjcCall|UIApplication|sharedInstance|ClassMethod=1}} is equivalent to using external symbol <tt>UIApp</tt>. The latter is often used in debugging environments such as [[Cycript]] for convenience.
 
== Event recording ==
{{Main|UIApplication/Event recording}}


[[UIApplication]] is a singleton object that represents the application.
UIApplication provides the <tt>-_addRecorder:</tt> and related methods to record user's events (as [[GSEvent]]s). Event playback is also supported, so it can be used as a macro system.


== Parameters for UIKit applications ==
== Suspension settings ==
{{function signature
|signature=-(BOOL)applicationSuspend:(GSEventRef)event settings:(NSMutableDictionary*)settings;
|firmware=2.0 –
}}
This method will be called before the app gets suspended. By default UIApplication doesn't contain this method. You have to implement this if needed. You can change the settings here, to generate the initial state of next resumption. This technique is used in many built-in apps. The recognized keys are:


UIApplicationMain recognizes the following these special flags:
{| class="wikitable"
{| class="wikitable"
|-
|-
! Flag
! Key !! Value type !! Usage
! Purpose
|-
| UISuspendedStatusBarModeKey || Integer || The initial status bar mode.
|-
| UISuspendedStatusBarOrientationKey || Integer || The initial status bar orientation.
|-
| kUISuspendedReturnToLastAppKey || Boolean || ?
|-
| UISuspendedRoleID || String || ? (kUISuspendedReturnToLastAppKey must be true for this to have any effects)
|-
|-
| <tt>-BuildDefaultPNG</tt>
| UISuspendedDefaultPNGKey || String || The file name of the default PNG image to use. For example, if you want to use <tt>Default-Landscape.png</tt> when the app starts, set this key to <tt>@"Default-Landscape"</tt>.
| Write the default PNG image to <tt>~/Library/Caches/AppSnapshots/''BundleID''.png</tt> (by calling <tt>-[UIApplication _writeApplicationDefaultPNGSnapshot]</tt> on start up).
|-
|-
| <tt>-RegisterForSystemEvents</tt>
|}
| Allow this app to receive system events which normally should be received by SpringBoard.
These values are written sent to SpringBoard with the <tt>GSSendApplicationSuspendedEvent</tt> function.
|}
 
If this method returns NO, the app will just be backgrounded. You must set the UIApplicationExitsOnSuspend key to YES in the application's Info.plist file on 4.0 and later for the app to be truly backgrounded. Otherwise, the default multitasking system will shut down networking activities and timers, among other things.
 
== Launching an application ==
 
To programmatically launch [[MobileSafari]]:
 
<source lang=objc>
[[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.mobilesafari" suspended:NO];
</source>
 
This is equivalent to using <tt>SBSLaunchApplicationWithIdentifier</tt>.


== References ==
== References ==
* Official reference: http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
* Official reference: http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
* Extra header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIApplication2.h
* Extra header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIApplication2.h
{{occlass|library=UIKit.framework|navbox=on}}

Latest revision as of 23:38, 7 September 2013

UIApplication is a singleton object that represents the application.

UIApp

Signature extern UIApplication* UIApp;
Available in 2.0 –

The method +[UIApplication sharedInstance] is equivalent to using external symbol UIApp. The latter is often used in debugging environments such as Cycript for convenience.

Event recording

UIApplication provides the -_addRecorder: and related methods to record user's events (as GSEvents). Event playback is also supported, so it can be used as a macro system.

Suspension settings

Signature -(BOOL)applicationSuspend:(GSEventRef)event settings:(NSMutableDictionary*)settings;
Available in 2.0 –

This method will be called before the app gets suspended. By default UIApplication doesn't contain this method. You have to implement this if needed. You can change the settings here, to generate the initial state of next resumption. This technique is used in many built-in apps. The recognized keys are:

Key Value type Usage
UISuspendedStatusBarModeKey Integer The initial status bar mode.
UISuspendedStatusBarOrientationKey Integer The initial status bar orientation.
kUISuspendedReturnToLastAppKey Boolean ?
UISuspendedRoleID String ? (kUISuspendedReturnToLastAppKey must be true for this to have any effects)
UISuspendedDefaultPNGKey String The file name of the default PNG image to use. For example, if you want to use Default-Landscape.png when the app starts, set this key to @"Default-Landscape".

These values are written sent to SpringBoard with the GSSendApplicationSuspendedEvent function.

If this method returns NO, the app will just be backgrounded. You must set the UIApplicationExitsOnSuspend key to YES in the application's Info.plist file on 4.0 and later for the app to be truly backgrounded. Otherwise, the default multitasking system will shut down networking activities and timers, among other things.

Launching an application

To programmatically launch MobileSafari:

[[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.mobilesafari" suspended:NO];

This is equivalent to using SBSLaunchApplicationWithIdentifier.

References