iOS9开放的新API--Spotlight使用指南

2020-01-14 17:32:24丽君

    
    [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler:^(NSError * error) {
        if (error) {
            NSLog(@"indexSearchableItems Error:%@",error.localizedDescription);
           
        }
    }];
}

 

 

  ========加载本地图片的使用方法========

 

 

复制代码 [self insertSearchableItem:UIImagePNGRepresentation([UIImage imageNamed:@"xxx.png"]) spotlightTitle:@"等风来" description:@"等风来描述" keywords:@[@"鲍鲸鲸",@"大丽花"] spotlightInfo:@"传递过去的值" domainId:@"com.wb.spotlight"];

 

 

  ========加载网络图片的使用方法========

 

 

复制代码  
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.easck.com/doc/pic/item/eaf81a4c510fd9f905f61934262dd42a2934a48e.jpg"]];
        [self insertSearchableItem:data spotlightTitle:@"等风来" description:@"等风来描述" keywords:@[@"鲍鲸鲸",@"大丽花"] spotlightInfo:@"传递过去的值" domainId:@"com.wb.spotlight"];
    });

 

 

  ========删除所有spotlight的方法========

 

 

复制代码
[[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error.localizedDescription);
}
}];

 

 

  ========删除指定的spotlight的方法========