SBApplication: Difference between revisions

From iPhone Development Wiki
m (K)
 
(15 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[[SBApplication]] is a class representing the application screen on the {{applink|SpringBoard}}. SBApplication is a subclass of [[SBDisplay]]. See [[SBDisplay]] for more info.
[[SBApplication]] is a class that represents individual applications. It contains anything you could possibly want to know about the application it represents.  


== Retrieving an instance of SBApplication ==
== Fetching SBApplications ==
To retrieve a known instance, you must go through [[SBApplicationController]]. For example, if the display ID of the application is known, you can use:
[[SBApplicationController]] holds all known instances of SBApplication. There will usually just be a single instance per currently-running application. An instance can be retrieved using the wanted-application's bundle identifier.
<source lang="objc">
<source lang="objc">
//iOS 7-
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithDisplayIdentifier:@"com.yourcompany.appname"];
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithDisplayIdentifier:@"com.yourcompany.appname"];
// iOS 8+
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithBundleIdentifier:@"com.yourcompany.appname"];
</source>
</source>


== Get all active applications ==
== Fetching Frontmost App's SBApplication Instance ==
{{function signature
This method will return the frontmost application's SBApplication instance. If no app is currently running <code>nil</code> will be returned. Internally it queries [[SBSceneManagerCoordinator]] to retrieve the application (if any) that is fulfilling the primary layout role.
|signature=-(NSArray*)_accessibilityRunningApplications;
<source lang="objc">
|firmware=3.0 –
[[SpringBoard sharedApplication] _accessibilityFrontMostApplication];
}}
</source>
{{function signature
|signature=-(SBApplication*)_accessibilityFrontMostApplication;
|firmware=3.2 –
}}


Getting active applications traditionally need to be done via the static function at <tt>0xeadc</tt>, or evaluate through the result of {{ObjcCall|SBApplicationController|allApplications}} and check if the <tt>pid</tt> is valid. Fortunately, starting from 3.0, the SpringBoard class provides a method {{ObjcCall|SpringBoard|_accessibilityRunningApplications}} which directly calls <tt>0xeadc</tt>. Therefore, you can get the array of active applications from this.
== Fetching All Instances ==
[[SBApplicationController]] can provide an array containing all known instances of SBApplication.  
<source lang="objc">
[[SBApplicationController sharedInstanceIfExists] runningApplications];
</source>


Starting from 3.2 one can also use {{ObjcCall|SpringBoard|_accessibilityFrontMostApplication}} to get the front most application. If you know the app you can check if [[app process] isFrontmost].
== Fetch "Now Playing" App ==
<source lang="objc">
SBApplication *nowPlayingApp = [[SBMediaController sharedInstance] nowPlayingApplication];
</source>


== Launching an SBApplication ==
== Launching an SBApplication ==
To launch an SBApplication you can use [[SBUIController]]:
[[SBUIController]] can be used to launch an SBApplication.
<source lang="objc">
SBApplication *appToLaunch = [[SBApplicationController sharedInstanceIfExists] runningApplications][0];
[[SBUIController sharedInstanceIfExists] activateApplication:appToLaunch];
</source>
 
== Classic Mode ==
 
Here are the constants that represent application classic mode depending on the screen type, retrieved from reversing <code>SBApplicationClassicModeDescription(NSInteger)</code> or <code>SBApplicationClassicModeForString(NSString *)</code> from [[SpringBoard.framework]].
 
<source lang="objc">
 
// The number suffix, if present, represents the diagonal size of the screen, in inches
typedef NS_ENUM(NSInteger, SBApplicationClassicMode) {
    SBApplicationClassicModeNone = 0,
    SBApplicationClassicModePhone = 1,
    SBApplicationClassicModePhone4 = 2,
    SBApplicationClassicModePhone4_7 = 3,
    SBApplicationClassicModePhone5_5 = 4,
    SBApplicationClassicModePhone5_8_Zoomed = 5, // rounded
    SBApplicationClassicModePhone5_8 = 6, // rounded
    SBApplicationClassicModePhone6_1 = 7, // rounded
    SBApplicationClassicModePhone6_5 = 8, // rounded
    SBApplicationClassicModePhone6_7 = 9, // rounded
    SBApplicationClassicModePad = 10,
    SBApplicationClassicModePad_10_5 = 11,
    SBApplicationClassicModePad_12_9 = 12,
    SBApplicationClassicModePad_11 = 13 // rounded
};
 
</source>
 
To disable launch animations simply apply the correct activation setting before calling <code>-activateApplication:</code>.
<source lang="objc">
[appToLaunch setFlag:1 forActivationSetting:1]; // flag 1 = ON, Activation Setting 1 = @"noAnimate"
</source>
 
'''Notes:'''
* This method will not respect parental control. However, you can determine if an SBApplication is restricted (parental locked) by using [[SBApplicationRestrictionController]], which [[SBApplicationController]] holds an instance of.
<source lang="objc">
SBApplication *appToCheck = [[SBApplicationController sharedInstanceIfExists] runningApplications][0];
BOOL appIsRestricted = [[[SBApplicationController sharedInstanceIfExists] restrictionController] isApplicationIdentifierRestricted:[appToCheck bundleIdentifier]];
</source>
 
'''Other Known Activation Flags'''
 
{| class="activationflags"
|-
! Flag ||    Setting
|-
| 1      ||    Launch without animations. 
|-
| 8      ||    Force launch animation to use app's context view instead of a snapshot.     
|-
| 11      ||    Delay launch animation.
|-
| 43      ||    Set the app as the "Now Playing" application.     
|}
 
== Useful Methods ==
These are a few of the useful items in SBApplication.
<source lang="objc">
<source lang="objc">
[[SBUIController sharedInstance] activateApplicationAnimated:app];
 
//the apps bundle id
- (NSString *)bundleIdentifier;
 
//is it SpringBoard's instance
- (BOOL)isSpringBoard;
 
//app location info
- (NSString *)path;
- (NSString *)dataContainerPath;
- (NSString *)bundleContainerPath;
- (NSString *)bundleVersion;
- (NSString *)sandboxPath; 
 
//general info
- (BOOL)isSetup;
- (BOOL)isMobilePhone;
- (BOOL)isFaceTime;
- (BOOL)behavesLikePhone;
- (BOOL)isWebApplication;
- (BOOL)isWatchApplication;
- (BOOL)isNowPlayingApplication;
- (BOOL)isNowRecordingApplication;
- (BOOL)showsProgress;
- (BOOL)isRecordingAudio;
- (BOOL)isRunning;
- (BOOL)hasStartedLaunching;
 
//the string displayed under the icon
- (NSString *)displayName;
 
//has it been launched at some point in SpringBoard's life
- (BOOL)hasBeenFrontmost;
 
//badge number
- (id)badgeNumberOrString;
 
//returns the app's FBScene instance, useful for doing context host view stuff
- (FBScene *)mainScene;
 
</source>
</source>
Note 1. this method will not respect parental control. You can look up the list of restricted apps using {{ObjcCall|SpringBoard|parentalControlsDisabledApplications}}, however.


Note 2. this method will only work if on the home screen. It will not work when already in an application.
== Application Info.plist ==
== Application Info.plist ==
SpringBoard will recognize the following Info.plist keys:
SpringBoard will recognize the following Info.plist keys:
* UISystemProvisioning
* UISystemProvisioning
* SBDemoRole<ref name="hunt">http://blogs.oreilly.com/iphone/2008/11/hunting-down-infoplist-prefere.html</ref>
* SBDemoRole<ref name="hunt">http://blogs.oreilly.com/iphone/2008/11/hunting-down-infoplist-prefere.html</ref>
Line 47: Line 153:


Starting from 3.2 these ''documented'' keys are also recognized:
Starting from 3.2 these ''documented'' keys are also recognized:
='-;0l9876t543211q`
 
* ProductType, UIDeviceFamily, DeviceFamily<ref>The keys UIDeviceFamily and DeviceFamily are private but equivalent to ProductType.</ref>
* ProductType, UIDeviceFamily, DeviceFamily<ref>The keys ProductType and DeviceFamily are private but equivalent to UIDeviceFamily.</ref>
* UIAppFonts
* UIAppFonts
* UIFileSharingEnabled
* UIFileSharingEnabled
Line 54: Line 160:


As of iOS 8, the following undocumented key is also recognized:
As of iOS 8, the following undocumented key is also recognized:
* _UILaunchAlwaysFullScreen<ref>http://pastebin.com/XmRqevnD</ref>
* _UILaunchAlwaysFullScreen<ref>http://pastebin.com/XmRqevnD</ref>
== Now Playing App Info ==
Getting the App info of the nowPlayingApp is now possible, thanks to SBMediaController's property (int _nowPlayingProcessPID)
To do so, you must use SBMediaPlayer in combination with SBApplication itself:
<source lang="objc">
int pid = [SBMediaPlayer sharedInstance].nowPlayingProcessPID
SBApplication *nowPlayingApp = [SBApplication applicationWithPid:pid];
</source>
Now, you can use many of SBApplication's useful methods (like -(id)displayName and -(id)bundleIdentifier) to retrieve app Info of the nowPlaying app.


== References ==
== References ==
<references />
<references />
* Header: http://github.com/kennytm/iphone-private-frameworks/blob/master/SpringBoard/SBApplication.h
* Header: https://github.com/theos/headers/blob/master/SpringBoard/SBApplication.h


{{occlass|library=SpringBoard.app|navbox=1}}
{{occlass|library=SpringBoard.app|navbox=1}}

Latest revision as of 08:10, 6 June 2021

SBApplication is a class that represents individual applications. It contains anything you could possibly want to know about the application it represents.

Fetching SBApplications

SBApplicationController holds all known instances of SBApplication. There will usually just be a single instance per currently-running application. An instance can be retrieved using the wanted-application's bundle identifier.

//iOS 7-
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithDisplayIdentifier:@"com.yourcompany.appname"];

// iOS 8+
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithBundleIdentifier:@"com.yourcompany.appname"];

Fetching Frontmost App's SBApplication Instance

This method will return the frontmost application's SBApplication instance. If no app is currently running nil will be returned. Internally it queries SBSceneManagerCoordinator to retrieve the application (if any) that is fulfilling the primary layout role.

[[SpringBoard sharedApplication] _accessibilityFrontMostApplication];

Fetching All Instances

SBApplicationController can provide an array containing all known instances of SBApplication.

[[SBApplicationController sharedInstanceIfExists] runningApplications];

Fetch "Now Playing" App

SBApplication *nowPlayingApp = [[SBMediaController sharedInstance] nowPlayingApplication];

Launching an SBApplication

SBUIController can be used to launch an SBApplication.

SBApplication *appToLaunch = [[SBApplicationController sharedInstanceIfExists] runningApplications][0];
[[SBUIController sharedInstanceIfExists] activateApplication:appToLaunch];

Classic Mode

Here are the constants that represent application classic mode depending on the screen type, retrieved from reversing SBApplicationClassicModeDescription(NSInteger) or SBApplicationClassicModeForString(NSString *) from SpringBoard.framework.

// The number suffix, if present, represents the diagonal size of the screen, in inches
typedef NS_ENUM(NSInteger, SBApplicationClassicMode) {
    SBApplicationClassicModeNone = 0,
    SBApplicationClassicModePhone = 1,
    SBApplicationClassicModePhone4 = 2,
    SBApplicationClassicModePhone4_7 = 3,
    SBApplicationClassicModePhone5_5 = 4,
    SBApplicationClassicModePhone5_8_Zoomed = 5, // rounded
    SBApplicationClassicModePhone5_8 = 6, // rounded
    SBApplicationClassicModePhone6_1 = 7, // rounded
    SBApplicationClassicModePhone6_5 = 8, // rounded
    SBApplicationClassicModePhone6_7 = 9, // rounded
    SBApplicationClassicModePad = 10,
    SBApplicationClassicModePad_10_5 = 11,
    SBApplicationClassicModePad_12_9 = 12,
    SBApplicationClassicModePad_11 = 13 // rounded
};

To disable launch animations simply apply the correct activation setting before calling -activateApplication:.

[appToLaunch setFlag:1 forActivationSetting:1]; // flag 1 = ON, Activation Setting 1 = @"noAnimate"

Notes:

SBApplication *appToCheck = [[SBApplicationController sharedInstanceIfExists] runningApplications][0];
BOOL appIsRestricted = [[[SBApplicationController sharedInstanceIfExists] restrictionController] isApplicationIdentifierRestricted:[appToCheck bundleIdentifier]];

Other Known Activation Flags

Flag Setting
1 Launch without animations.
8 Force launch animation to use app's context view instead of a snapshot.
11 Delay launch animation.
43 Set the app as the "Now Playing" application.

Useful Methods

These are a few of the useful items in SBApplication.

//the apps bundle id
- (NSString *)bundleIdentifier; 

//is it SpringBoard's instance
- (BOOL)isSpringBoard; 

//app location info
- (NSString *)path;
- (NSString *)dataContainerPath;
- (NSString *)bundleContainerPath;
- (NSString *)bundleVersion;
- (NSString *)sandboxPath;  

//general info
- (BOOL)isSetup;
- (BOOL)isMobilePhone;
- (BOOL)isFaceTime;
- (BOOL)behavesLikePhone;
- (BOOL)isWebApplication;
- (BOOL)isWatchApplication;
- (BOOL)isNowPlayingApplication;
- (BOOL)isNowRecordingApplication;
- (BOOL)showsProgress;
- (BOOL)isRecordingAudio;
- (BOOL)isRunning;
- (BOOL)hasStartedLaunching;

//the string displayed under the icon
- (NSString *)displayName;

//has it been launched at some point in SpringBoard's life
- (BOOL)hasBeenFrontmost;

//badge number
- (id)badgeNumberOrString;

//returns the app's FBScene instance, useful for doing context host view stuff
- (FBScene *)mainScene;

Application Info.plist

SpringBoard will recognize the following Info.plist keys:

Starting from 3.2 these documented keys are also recognized:

  • ProductType, UIDeviceFamily, DeviceFamily[6]
  • UIAppFonts
  • UIFileSharingEnabled
  • UISupportedInterfaceOrientations

As of iOS 8, the following undocumented key is also recognized:

  • _UILaunchAlwaysFullScreen[7]

References