2

Is there any way to determine "how" an app is launched or made active (i.e. homescreen tap, four finger swipe, siri, etc...)?

There's this thread which is similar (Determining whether iOS application was launched via Siri), however not too many answers in this. There's also this for Mac OSX (How can a Mac app determine the method used to launch it?) but I need something similar for iOS.

I've also skimmed through this (https://developer.apple.com/library/ios/DOCUMENTATION/iPhone/conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW3) though I coudn't find anything that recognizes "how" the app was launched.

Thanks in advance.

Community
  • 1
  • 1

1 Answers1

2

You can figure out that an app was launched from a URL in another application using the AppDelegate method:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation { } 

Additionally, application:DidFinishLaunchingWithOptions: has options, which are keys that you can find here that tell you reasons why the app launched.

Those keys are:

NSString *const UIApplicationLaunchOptionsURLKey;
NSString *const UIApplicationLaunchOptionsSourceApplicationKey;
NSString *const UIApplicationLaunchOptionsRemoteNotificationKey;
NSString *const UIApplicationLaunchOptionsAnnotationKey;
NSString *const UIApplicationLaunchOptionsLocalNotificationKey;
NSString *const UIApplicationLaunchOptionsLocationKey;
NSString *const UIApplicationLaunchOptionsNewsstandDownloadsKey;
NSString *const UIApplicationLaunchOptionsBluetoothCentralsKey;
NSString *const UIApplicationLaunchOptionsBluetoothPeripheralsKey;

You can check for them with if statements when the app launches.

AdamG
  • 3,718
  • 2
  • 18
  • 28