I'm trying to add my own activity to Spotlight search results on osx 10.11. But after a lot of tries I couldn't got to be in Spotlight search results not by keywords search, not by title search.
{
self.userActivity = [[NSUserActivity alloc] initWithActivityType:@"Reverse DNS keyword"];
self.userActivity.title = @"Some title";
self.userActivity.keywords = [NSSet setWithArray: @[@"Some keywords"]];
self.userActivity.eligibleForSearch = YES;
self.userActivity.eligibleForHandoff = YES;
self.userActivity.eligibleForPublicIndexing = YES;
self.userActivity.userInfo = @{@"name" : @"Some name"};
self.userActivity.delegate = self;
self.userActivity.requiredUserInfoKeys =[NSSet setWithArray: @[@"name"]];
self.userActivity.needsSave = YES;
[self.userActivity becomeCurrent];
NSApp.userActivity = self.userActivity;
}
- (void)userActivityWillSave:(NSUserActivity *)userActivity
{
userActivity.userInfo = @{@"name" : @"Some name"};
}
Also I've updated Info.plist with NSUserActivityTypes array and item from the initWithActivityType: argument
Also I've noticed that in Console sometime appears messages:
16/09/2016 13:14:49.731 Caching encoded userInfo to use until we are marked dirty again (UAUserActivity.m #1567)
16/09/2016 13:14:49.731 Returning cached encoded userInfo (UAUserActivity.m #1508)
After a searched a lot, eventually I found answer on my question in TN2416:
**Are these new Search APIs available on OS X?**
CoreSpotlight and the search functionality of NSUserActivity are not supported on OS X. However, web search results may be shown on OS X.