1 Reply
      Latest reply on Aug 13, 2019 6:49 PM by ay8s
      krageshwar Level 1 Level 1 (0 points)



        I am working on multiple windows in iPad. For push notifications to be delivered in specific window, we need to set "target-content-id" in APNS payload and set activation condition predicate for that window scene. I set the target content id for the window scene for my specific window. Now after the push notification is delivered, when I tap on the notification, it will redirect to the scene where target content id is set.


        func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)


        The above method is called when we tap on notification. In this method, how do we get the targetted UIScene instance for which the notification is delivered?


        Setting target content id in window like below:


                  if #available(iOS 13.0, *) {

                    if let conditions = view.window?.windowScene?.activationConditions {

                        let predicate = NSPredicate(format: "SELF == \"targetContentId\"")

                        conditions.canActivateForTargetContentIdentifierPredicate = predicate


                } else {

                    // Fallback on earlier versions



        As of now, I am using the below code to find the window, by comparing the window scene's target content id with notification's target content id's predicate format. But in this case, if we have two windows and both the windows have same target content id, then I am checking keywindow property and returning the window. I don't think this is the correct way.


        private func getTargetContentWindow(notification: UNNotification) -> UIWindow {

                var window: UIWindow!

                for scene in UIApplication.shared.connectedScenes where (scene as? UIWindowScene) != nil {

                    let windowScene = scene as! UIWindowScene

                    window = windowScene.windows.first?.isKeyWindow == true ? windowScene.windows.first! : (window ?? nil)

                    if let targetContentId = notification.request.content.targetContentIdentifier {

                        let targetContentPredicateFormat = "SELF == \"\(targetContentId)\""

                        if targetContentPredicateFormat == windowScene.activationConditions.canActivateForTargetContentIdentifierPredicate.predicateFormat, let windowObj = windowScene.windows.first {

                            window = windowObj





                return window



        I checked 'sceneWillEnterForeground(_ scene: UIScene)' and 'sceneDidBecomeActive(_ scene: UIScene)' methods, both are called after the push notification 'userNotificationCenter_ center: UNUserNotificationCenter'.......) methods. So I am not finding correct scene instance. Also I didn't see any new push notification method with scenes.


        Is there any other way to get correct UIScene instance?


        Anybody please share your experiences about target content id in multiwindow.