NSUserActivity没有在osx上编入索引

时间:2016-09-16 10:39:58

标签: ios macos cocoa cocoa-touch nsuseractivity

我试图将自己的活动添加到osx 10.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"};
}

我还使用来自initWithActivityType:参数的NSUserActivityTypes数组和项更新了Info.plist

我也注意到在控制台中有时出现消息:

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)

1 个答案:

答案 0 :(得分:1)

经过大量搜索,最终我在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.