Skip to content

Commit 72b3288

Browse files
committed
Stop donating screen activities as Siri predictions
The Jetpack app's App Shortcuts are the modern replacement for Siri suggestions, so the prediction donation, the suggested invocation phrases, and the now-unused MobileCoreServices import are removed. The system keeps previously donated suggestions until they are explicitly deleted, so all saved user activities are deleted once at launch and upgrading users do not keep stale suggestions. The screen activities remain eligible for Spotlight search, whose index is separate and unaffected.
1 parent 42bfcd5 commit 72b3288

2 files changed

Lines changed: 14 additions & 33 deletions

File tree

Modules/Sources/WordPressData/Swift/SearchableActivityConvertable.swift

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import UIKit
22
import CoreSpotlight
3-
import Intents
4-
import MobileCoreServices
53
import UniformTypeIdentifiers
64

75
/// Custom NSUSerActivity types for the WPiOS. Primarily used for navigation points.
@@ -17,32 +15,6 @@ public enum WPActivityType: String {
1715
case notifications = "org.wordpress.notifications"
1816
}
1917

20-
extension WPActivityType {
21-
var suggestedInvocationPhrase: String {
22-
switch self {
23-
case .siteList:
24-
return NSLocalizedString("My Sites in WordPress", comment: "Siri Suggestion to open My Sites")
25-
case .siteDetails:
26-
return NSLocalizedString("WordPress Site Details", comment: "Siri Suggestion to open My Sites")
27-
case .reader:
28-
return NSLocalizedString("WordPress Reader", comment: "Siri Suggestion to open My Sites")
29-
case .me:
30-
return NSLocalizedString("WordPress Profile", comment: "Siri Suggestion to open Me tab")
31-
case .appSettings:
32-
return NSLocalizedString("WordPress App Settings", comment: "Siri Suggestion to open App Settings")
33-
case .notificationSettings:
34-
return NSLocalizedString(
35-
"WordPress Notification Settings",
36-
comment: "Siri Suggestion to open Notification Settings"
37-
)
38-
case .support:
39-
return NSLocalizedString("WordPress Help", comment: "Siri Suggestion to open Support")
40-
case .notifications:
41-
return NSLocalizedString("WordPress Notifications", comment: "Siri Suggestion to open Notifications")
42-
}
43-
}
44-
}
45-
4618
/// NSUserActivity userInfo keys
4719
///
4820
public enum WPActivityUserInfoKeys: String {
@@ -108,11 +80,6 @@ public extension SearchableActivityConvertable where Self: UIViewController {
10880

10981
activity.isEligibleForSearch = true
11082
activity.isEligibleForHandoff = false
111-
activity.isEligibleForPrediction = true
112-
113-
if let wpActivityType = WPActivityType(rawValue: activityType) {
114-
activity.suggestedInvocationPhrase = wpActivityType.suggestedInvocationPhrase
115-
}
11683

11784
// Set the UIViewController's userActivity property, which is defined in UIResponder. Doing this allows
11885
// UIKit to automagically manage this user activity (e.g. making it current when needed)

WordPress/Classes/System/WordPressAppDelegate.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
109109

110110
MemoryCache.shared.register()
111111
MediaImageService.migrateCacheIfNeeded()
112+
purgeLegacySiriDonationsIfNeeded()
112113
PostCoordinator.shared.delegate = self
113114

114115
// Start CrashLogging as soon as possible (in case a crash happens during startup)
@@ -414,6 +415,19 @@ public class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
414415
AccountService(coreDataStack: ContextManager.shared).mergeDuplicatesIfNecessary()
415416
}
416417

418+
/// Deletes the user activities donated as Siri predictions by earlier app versions,
419+
/// because the app no longer donates predictions and the system keeps the old
420+
/// suggestions until they are explicitly deleted.
421+
// TODO: Remove this cleanup after a few releases.
422+
private func purgeLegacySiriDonationsIfNeeded() {
423+
let didPurgeKey = "did-purge-legacy-siri-donations"
424+
guard !UserDefaults.standard.bool(forKey: didPurgeKey) else {
425+
return
426+
}
427+
UserDefaults.standard.set(true, forKey: didPurgeKey)
428+
NSUserActivity.deleteAllSavedUserActivities {}
429+
}
430+
417431
private func setupPingHub() {
418432
pingHubManager = PingHubManager()
419433
}

0 commit comments

Comments
 (0)