core spotlight
_data = @[@"图片1" ,@"图片2" , @"图片3"];
NSMutableArray * arr = [NSMutableArray arrayWithCapacity:10];
[_data enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
CSSearchableItemAttributeSet * attributeSet = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:@"view"];
attributeSet.title = obj;
NSLog(@"%@" , obj);
attributeSet.contentDescription = [NSString stringWithFormat:NSLocalizedString(@"easy way to open %@", nil),obj];
UIImage * thumbImage = [UIImage imageNamed:[NSString stringWithFormat: @"%@.jpg" , obj]];
attributeSet.thumbnailData = UIImagePNGRepresentation(thumbImage);
CSSearchableItem * item = [[CSSearchableItem alloc]initWithUniqueIdentifier:[NSString stringWithFormat:@"1%@" , obj] domainIdentifier:@"demo" attributeSet:attributeSet];
[arr addObject:item];
}];
[[CSSearchableIndex defaultSearchableIndex]indexSearchableItems:arr completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"%@ ", error.localizedDescription);
}
}];
实现:(实现跳转)
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
NSLog(@"%@" , userActivity.userInfo);
NSString * indetifier = userActivity.userInfo[@"kCSSearchableItemActivityIdentifier"];
NSString * subStr = [indetifier substringFromIndex:0];
NSLog(@"%@" , subStr);
UINavigationController * nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
if ([subStr isEqualToString:@"图片1"]) {
[nav popToRootViewControllerAnimated:YES];
}else if ([subStr isEqualToString:@"图片2"]){
BG2ViewController * bg2 = [[BG2ViewController alloc]init];
[nav pushViewController:bg2 animated:YES];
}else{
BG3ViewController * bg3 = [[BG3ViewController alloc]init];
[nav pushViewController:bg3 animated:YES];
}
return YES;
}