问题描述
我使用 NSUserActivity
为要搜索的用户活动编制索引.我找到了一种删除特定 NSUserActivity
的解决方案,将具有 relatedUniqueIdentifier
的 CSSearchableItemAttributeSet
分配给 NSUserActivity
的方法:
I use NSUserActivity
to index a user activity for searching. I found a solution to delete a specific NSUserActivity
, assign a CSSearchableItemAttributeSet
with relatedUniqueIdentifier
to NSUserActivity
:
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeContact as String)
attributeSet.relatedUniqueIdentifier = objectId
let activity = NSUserActivity(activityType: Employee.domainIdentifier)
activity.title = name
activity.userInfo = userActivityUserInfo
activity.keywords = [email, department]
activity.contentAttributeSet = attributeSet
并使用
[[CSSearchableIndex defaultSearchableIndex]
deleteSearchableItemsWithIdentifiers: objectId completionHandler:^(NSError *deletionError) {
if (deletionError) {
NSLog(@"Could not delete items from the search index with error %@", deletionError);
}
}];
我不知道这是否是正确的解决方案.您是否有更好的解决方案来删除特定的 NSUserActivity
搜索索引?
I don't know if it is a right solution or not. Do you have a better solution to delete a specific NSUserActivity
search index?
推荐答案
从iOS 12开始,有两种方法可以删除 NSUserActivity
As of iOS 12, there are 2 methods to delete NSUserActivity
class func deleteAllSavedUserActivities(completionHandler: () -> Void)
class func deleteSavedUserActivities(withPersistentIdentifiers: [NSUserActivityPersistentIdentifier], completionHandler: () -> Void)
文档注释删除所有由Core Spotlight存储或捐赠为Siri快捷方式的用户活动."
The docs note "Deletes all user activities stored by Core Spotlight or donated as Siri shortcuts."
https://developer.apple.com/documentation/foundation/nsuseractivity
这篇关于如何删除特定的NSUserActivity搜索索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!