我试图在OSX10.11上添加我自己的活动到Spotlight搜索结果中。但是经过多次尝试,我无法进入Spotlight搜索结果--不是关键字搜索,也不是标题搜索。
{
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"};
}此外,我还从Info.plist :参数中用NSUserActivityTypes数组和项更新了initWithActivityType
我还注意到,在控制台中有时会出现消息:
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)发布于 2016-09-22 08:00:32
经过多次搜索,我终于在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.https://stackoverflow.com/questions/39529454
复制相似问题