我想让我的应用程序为 Spotlight 索引做好准备,所以我得到了下面的代码来向 Core Spotlight 添加一个项目:
CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:(NSString *)kUTTypeImage];
attributeSet.title = appName;
attributeSet.contentDescription = appDescription;
attributeSet.keywords = appKeywordsArray;
UIImage *image = [UIImage imageNamed:@"tile-blue.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;
CSSearchableItem *item = [[CSSearchableItem alloc]initWithUniqueIdentifier:appIdentifier domainIdentifier:@"com.myapp" attributeSet:attributeSet];
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler: ^(NSError * __nullable error) {
if (!error)
NSLog(@"Search item indexed");
}];
因此,每次运行时,它都会记录 Search item indexed
因此在索引期间没有错误。但是,当我去 Spotlight 中搜索时,什么也没有显示。我做错了什么?
最佳答案
目前 Spotlight 似乎无法在某些设备上使用。
您的代码应该可以在模拟器上运行。
关于ios - CoreSpotlight 索引由于某种原因无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30941058/