我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
搜索索引吗?