0

I want to catch launchOptions like in didFinishLaunchingWithOptions but in applicationDidBecomeActive (when my app take focus). For example, i open a document in Box. Then, i select "Open with" and select my app. Then my app take focus.

How can i recover launchOptions in my UIApplicationDelegate?

Thanks

ApheX
  • 685
  • 2
  • 10
  • 26

2 Answers2

3

If your app is not running and it is opened via another app, applicationDidBecomeActive is called and you get access to launchOptions. The app will then call application:openURL:sourceApplication:annotation:.

But if your app is in the background and simply becomes active, only application:openURL:sourceApplication:annotation: is called so you don't get any launchOptions. You should be able to get all the details you need though from the paramaters of application:openURL:sourceApplication:annotation:.

Full details from application:openURL:sourceApplication:annotation: documentation:

If an application is launched as a result of another application requesting it to open a URL resource, UIApplication first sends the application a application:didFinishLaunchingWithOptions: message and then it invokes this method. This method supplies the delegate of the handling application with the bundle ID of the source application as well as any annotation information from that application. If an application is already running when it receives a request to open a URL, this method is called but application:didFinishLaunchingWithOptions: isn’t.

Karl Monaghan
  • 880
  • 9
  • 14
1

If you're opening your app from an external app you will need to use URL schemes. This will open your app, no matter if it was left running in the background or in fact it was terminated (chances are this also happens).

With this technique, the method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation will be called in your App delegate.

Look that method up in the documentation to find out more about the parameters you can pass to your app. Usually you'd use a url you could analyse and act accordingly. But if you need to pass some more data, you can always use the annotation parameter, which is a plist you can convert into a dictionary and extract anything you want from it.