From eec2adbfd9ed4bd9a8e4977d4fbc9e7808248169 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 2 Jun 2024 10:10:16 -0700 Subject: [PATCH] Set target content identifiers on scenes/activities --- NotificationExtension/NotificationService.swift | 1 + Tusker/AppDelegate.swift | 7 ++++++- Tusker/Scenes/AuxiliarySceneDelegate.swift | 3 ++- Tusker/Scenes/ComposeSceneDelegate.swift | 2 ++ Tusker/Scenes/MainSceneDelegate.swift | 2 ++ Tusker/Shortcuts/NSUserActivity+Extensions.swift | 1 + 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NotificationExtension/NotificationService.swift b/NotificationExtension/NotificationService.swift index be2c6e43..965c1f92 100644 --- a/NotificationExtension/NotificationService.swift +++ b/NotificationExtension/NotificationService.swift @@ -63,6 +63,7 @@ class NotificationService: UNNotificationServiceExtension { mutableContent.body = notification.body mutableContent.userInfo["notificationID"] = notification.notificationID mutableContent.userInfo["accountID"] = accountID + mutableContent.targetContentIdentifier = accountID let task = Task { await updateNotificationContent(mutableContent, account: account, push: notification) diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index c24d1d9d..f33ee29e 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -295,7 +295,12 @@ extension AppDelegate: UNUserNotificationCenterDelegate { rootViewController.getNavigationController().pushViewController(vc, animated: false) } else { let activity = UserActivityManager.showNotificationActivity(id: notificationID, accountID: accountID) - UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil) + if #available(iOS 17.0, *) { + let request = UISceneSessionActivationRequest(userActivity: activity) + UIApplication.shared.activateSceneSession(for: request) + } else { + UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil) + } } completionHandler() } diff --git a/Tusker/Scenes/AuxiliarySceneDelegate.swift b/Tusker/Scenes/AuxiliarySceneDelegate.swift index 284516a7..2b48bde0 100644 --- a/Tusker/Scenes/AuxiliarySceneDelegate.swift +++ b/Tusker/Scenes/AuxiliarySceneDelegate.swift @@ -32,8 +32,9 @@ class AuxiliarySceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDel } launchActivity = activity + scene.activationConditions.canActivateForTargetContentIdentifierPredicate = NSPredicate(value: false) + let account: UserAccountInfo - if let activityAccount = UserActivityManager.getAccount(from: activity) { account = activityAccount } else if let mostRecent = UserAccountsManager.shared.getMostRecentAccount() { diff --git a/Tusker/Scenes/ComposeSceneDelegate.swift b/Tusker/Scenes/ComposeSceneDelegate.swift index bea636f1..b86d95e6 100644 --- a/Tusker/Scenes/ComposeSceneDelegate.swift +++ b/Tusker/Scenes/ComposeSceneDelegate.swift @@ -29,6 +29,8 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDeleg return } + scene.activationConditions.canActivateForTargetContentIdentifierPredicate = NSPredicate(value: false) + let account: UserAccountInfo let controller: MastodonController let draft: Draft? diff --git a/Tusker/Scenes/MainSceneDelegate.swift b/Tusker/Scenes/MainSceneDelegate.swift index b83de24c..3eddbb75 100644 --- a/Tusker/Scenes/MainSceneDelegate.swift +++ b/Tusker/Scenes/MainSceneDelegate.swift @@ -225,6 +225,8 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate window!.windowScene!.title = account.instanceURL.host! } + window!.windowScene!.activationConditions.prefersToActivateForTargetContentIdentifierPredicate = NSPredicate(format: "self == %@", account.id) + if let container = window?.rootViewController as? AccountSwitchingContainerViewController { let direction: AccountSwitchingContainerViewController.AnimationDirection if animated, diff --git a/Tusker/Shortcuts/NSUserActivity+Extensions.swift b/Tusker/Shortcuts/NSUserActivity+Extensions.swift index d1dcacc2..7a460a72 100644 --- a/Tusker/Shortcuts/NSUserActivity+Extensions.swift +++ b/Tusker/Shortcuts/NSUserActivity+Extensions.swift @@ -39,6 +39,7 @@ extension NSUserActivity { self.userInfo = [ "accountID": accountID ] + self.targetContentIdentifier = accountID } @MainActor