我使用NSUserActivity
索引用户搜索活动。我找到了删除特定NSUserActivity
的解决方案,将CSSearchableItemAttributeSet
与relatedUniqueIdentifier
分配给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
搜索索引?
答案 0 :(得分:0)
从iOS 12开始,有两种方法可以删除NSUserActivity
class func deleteAllSavedUserActivities(completionHandler: () -> Void)
class func deleteSavedUserActivities(withPersistentIdentifiers: [NSUserActivityPersistentIdentifier], completionHandler: () -> Void)
文档注释“删除所有由Core Spotlight存储或捐赠为Siri快捷方式的用户活动。”
https://developer.apple.com/documentation/foundation/nsuseractivity