我的情况非常简单:我使用下一个函数
private func launchActivity(_ id: String, title: String, invocPhrase: String) {
userActivity = NSUserActivity(activityType: "Open_bank")
userActivity?.title = title
userActivity?.userInfo = ["id": id]
if #available(iOS 12.0, *) {
userActivity?.suggestedInvocationPhrase = invocPhrase
userActivity?.isEligibleForPrediction = true
userActivity?.persistentIdentifier = id
} else {
//Can't actually invoke this block
}
}
创建某个userActivity,然后将其添加到Siri中,这样就可以被by调用invocPhrase
。这是执行此操作的函数。
func presentAddOpenBankToSiriVC() {
guard let userActivity = self.userActivity else { return }
if #available(iOS 12.0, *) {
let shortcut = INShortcut(userActivity: userActivity)
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
viewController.modalPresentationStyle = .formSheet
viewController.delegate = self
present(viewController, animated: true, completion: nil)
} else {
//Can't actually invoke this block
}
}
后来我尝试删除它(以及所有其他用户活动)
NSUserActivity.deleteAllSavedUserActivities {}
它只是不会删除任何用户活动,这与 Apple 文档 https://developer.apple.com/documentation/sirikit/deleting_donated_shortcuts中所写的相反
其实一开始我试过一个方法
deleteSavedUserActivities(withPersistentIdentifiers:completionHandler:)
使用 userActivity 的 persistentIdentifier,但显然也无济于事。
我不知道为什么它拒绝让步,但会感谢任何帮助或提示