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
SBApplication: Difference between revisions - iPhone Development Wiki

SBApplication: Difference between revisions

From iPhone Development Wiki
(A lot of the information on this page was super old and outdated or just incorrect. I brought most of the stuff up to date, and i'll add a lot more to this page over the next few days.)
mNo edit summary
Line 4: Line 4:
[[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.
[[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 9+
//iOS 7-
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithDisplayIdentifier:@"com.yourcompany.appname"];
SBApplication* app = [[SBApplicationController sharedInstance] applicationWithDisplayIdentifier:@"com.yourcompany.appname"];


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

Revision as of 15:24, 13 May 2017

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];

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