Spotlight

何为App Search?在iOS9之前,用户通过spotlight只能搜索app的名字,或者苹果自带app的一些内容,比如搜索通讯录、备忘录中的内容。iOS9开始,用户可以通过spotlight搜索网页内容或者任何app内的数据。


Paste_Image.png

如图,网上找的.

有空再加注释

- (void)spotlight{
    CSSearchableItemAttributeSet *firstSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:@"firstSet"];
    firstSet.title = @"主人,世上只有主人好";
    firstSet.contentDescription = @"主人不要冷落我,点点我嘛";
    firstSet.thumbnailData = UIImagePNGRepresentation([UIImage imageNamed:@"没有"]);
    NSArray * firstSearchKey = @[@"直播",@"美女",@"QQ"];
    firstSet.contactKeywords = firstSearchKey;
    CSSearchableItem *firstItem = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"firstItem" domainIdentifier:@"first" attributeSet:firstSet];
    
    CSSearchableItemAttributeSet *secondSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:@"secondSet"];
    secondSet.title = @"bibi求宠幸";
    secondSet.contentDescription = @"主人,点我有惊喜呦";
    secondSet.thumbnailData =  UIImagePNGRepresentation([UIImage imageNamed:@"没有"]);
    NSArray *secondKey = @[@"微信",@"视频",@"支付宝"];
    secondSet.contactKeywords = secondKey;
    CSSearchableItem *secondItem = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"secondItem" domainIdentifier:@"second" attributeSet:secondSet];
    
    
    NSArray *items = @[firstItem,secondItem];
    
    [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:items completionHandler:^(NSError * _Nullable error) {
        if (error) {
            DLog(@"%@,搜索设置失败");
        }else{
            DLog(@"搜索设置成功");
        }
    }];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{
    NSString *idetifier  = userActivity.userInfo[@"kCSSearchableItemActivityIdentifier"];
    NSLog(@"%@搜索标识符",idetifier);
    
    if ([idetifier isEqualToString:@"firstItem"]) {
        DLog(@"点击111%@",self.window.rootViewController);
        DLog(@"%@",[self getsCurrentVC]);
        
        
    }else if ([idetifier isEqualToString:@"secondItem"]){
        DLog(@"点击222");
        DLog(@"%@",[self getsCurrentVC]);
    }
    

    
    return YES;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容