ios - 如何删除特定的NSUserActivity搜索索引?

标签 ios corespotlight nsuseractivity

我使用NSUserActivity索引要搜索的用户 Activity 。我找到了删除特定NSUserActivity的解决方案,将带有CSSearchableItemAttributeSetrelatedUniqueIdentifier分配给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搜索索引?

最佳答案

从iOS 12开始,有2种删除NSUserActivity的方法

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

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

文档注释“删除了由Core Spotlight存储或捐赠为Siri快捷方式的所有用户 Activity ”。

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

关于ios - 如何删除特定的NSUserActivity搜索索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34647405/

相关文章:

IOS 在 AppDelegate.m 中使用 ViewController.m 的方法?

java - 读取war web项目类路径中的APN证书文件

iphone - 如何禁用 UIBarButtonItem?

objective-c - NSUserActivity 和 CoreSpotlight 的使用

iphone - iOS : Custom button on Navigation Controller is only visible on 1 view controller and not on other View Controllers

ios - Spotlight 搜索 - 深层链接集成

ios - Spotlight 搜索在 iOS 9.1 iPad mini 中不起作用

ios10 swift 3核心聚光灯搜索无法获得nsuseractivity的标题

ios - 如何预定义应该用于触发 Siri 的某些 Action 的某些短语

ios - NSUserActivity 缺少 contentAttributeSet 属性