I want to get my app ready for spotlight indexing, so I've got the code below to add an item to 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");
}];
So, every time this runs, it logs Search item indexed
so there are no errors during the indexing. However, when I go and search in Spotlight, nothing shows up. What am I doing wrong?
At the moment Spotlight seems to not work on some devices.
Your code should work on the simulator.