Lifecycle Behaviour Opening an file associated with an Application

When creating a UTI in UIKit for iOS and associating the UTI with the application(using CFBundleDocumentTypes), I've noticed the following behaviour:

  • If the application is already running, on opening a file associated with the app, only the OpenUrl delegate method gets called
  • When the app is in the terminated state, when an associated file is opened, it triggers  the “WillFinishLaunching”, “DidFinishLaunching” and then the “OpenUrl” delegate method

In both cases we get the file or a list of files at the OpenUrl stage.

This is unlike the AppKit behavior in Macos, where if files are dropped on the icon and the application is ‘launched’ – you get the file list BEFORE ‘DidFinishLaunching’, and files dropped on ‘running application’ is after DidFinishLaunching.

Is this behavior engineered to be different or am I missing something here?

Quoting a line from the UIKit OpenUrl page:

This method is not called if your implementations return NO from both the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods. (If only one of the two methods is implemented, its return value determines whether this method is called.)

Does this mean that we should access the URLs sent while opening the file before initializing the application(ie. in didFinishLaunchingWithOptions)

Is this behavior engineered to be different or am I missing something here?

Yes, the behavior is different and what you are seeing is expected.

Does this mean that we should access the URLs sent while opening the file before initializing the application(ie. in didFinishLaunchingWithOptions)

You should wait to access the URLs until -application:openURL:options: is called. For some URLs there is a resolution process that needs to happen, and that resolution process does not take place in the application-lifecycle code path unless you return YES from one of those methods. If you access the URL from the launch options dictionary the resolution will not have taken place yet.

Note, that's different than scene-lifecycle. There, we attempt to do the resolution process before the scene connects, so that if a UIOpenURLContext is present in UISceneConnectionOptions the URL is already resolved.

Lifecycle Behaviour Opening an file associated with an Application
 
 
Q