application(_:didFinishLaunchingWithOptions:) launchOptions is nil when app supports scenes

our app support silent push, and we use below code to get if app is launched by silent push:

        if let remoteNotification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [AnyHashable: Any],
           let aps = remoteNotification["aps"] as? [AnyHashable: Any],
           let contentAvailable = aps["content-available"] as? Int,
           contentAvailable == 1 {
            isSilentNotification = true
        }

when app is launch and call:

application(_:didFinishLaunchingWithOptions:)

but when migrate to UIScene, the launchOptions is always nil, and we can not get to know if app is launched by silent push; I read the develop doc:

it says:

If the app supports scenes, this is nil.

Continue using UIApplicationDelegate's application(_:didReceiveRemoteNotification:fetchCompletionHandler:) to process silent remote notifications after scene connection.

but the time for method calling

application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

id too late.

So except in didReceiveRemoteNotification method calling:

application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

are there any other ways to obtain the silent push flag when app is launch and has not didReceiveRemoteNotification call back.

This is now how it is going to work. If your app has scene support, launch options will be nil (for all cases), and instead scene(_:willConnectTo:options:) will receive the options.

Silent notifications is a different matter. As the system will call the didReceiveRemoteNotification delegate function, you can determine why the app has been launched by the call of that function.

Keep in mind didReceiveRemoteNotification will be called whether the app is launched or already suspended in memory, so if you specifically need the know the reason for the launch, you would want to implement a flagging mechanism between didFinishLaunching and didReceiveRemoteNotification

application(_:didFinishLaunchingWithOptions:) launchOptions is nil when app supports scenes
 
 
Q