How to delete a specific NSUserActivity search index?

隐身守侯 提交于 2020-01-04 10:05:24

问题


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

And delete it use

[[CSSearchableIndex defaultSearchableIndex] 
deleteSearchableItemsWithIdentifiers: objectId completionHandler:^(NSError *deletionError) {  
        if (deletionError) {  
            NSLog(@"Could not delete items from the search index with error %@", deletionError);  
        }  
    }]; 

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?


回答1:


As of iOS 12, there are 2 methods to delete NSUserActivity

class func deleteAllSavedUserActivities(completionHandler: () -> Void)

class func deleteSavedUserActivities(withPersistentIdentifiers: [NSUserActivityPersistentIdentifier], completionHandler: () -> Void)

The docs note "Deletes all user activities stored by Core Spotlight or donated as Siri shortcuts."

https://developer.apple.com/documentation/foundation/nsuseractivity



来源:https://stackoverflow.com/questions/34647405/how-to-delete-a-specific-nsuseractivity-search-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!