源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-07-16 15:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS9开放的新API--Spotlight使用指南
1.Spotloight是什么?   Spotlight在iOS9上做了一些新的改进, 也就是开放了一些新的API, 通过Core Spotlight Framework你可以在你的app中集成Spotlight。集成Spotlight的App可以在Spotlight中搜索App的内容,并且通过内容打开相关页面。   Demo演示   [img]http://files.jb51.net/file_images/article/201511/2015111416444729.gif[/img] 2.如何集成Spotlight   a.添加所需要的框架 
[url=http://hiphotos.baidu.com/doc/pic/item/eaf81a4c510fd9f905f61934262dd42a2934a48e.jpg]http://hiphotos.baidu.com/doc/pic/item/eaf81a4c510fd9f905f61934262dd42a2934a48e.jpg[/url]"]];         [self insertSearchableItem:data spotlightTitle:@"等风来" description:@"等风来描述" keywords:@[@"鲍鲸鲸",@"大丽花"] spotlightInfo:@"传递过去的值" domainId:@"com.wb.spotlight"];     });
[i]  ========删除所有spotlight的方法========[/i]
[u]复制代码[/u] 代码如下:
[[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:^(NSError * _Nullable error) { if (error) { NSLog(@"%@", error.localizedDescription); } }];
[i]  ========删除指定的spotlight的方法========[/i]
[u]复制代码[/u] 代码如下:
[[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithDomainIdentifiers:@"domainId" completionHandler:^(NSError * _Nullable error) { if (error) { NSLog(@"%@", error.localizedDescription); } }];
[i]  ========点击spotlight后的响应方法========[/i]
[u]复制代码[/u] 代码如下:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) { NSString *uniqueIdentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier]; // 接受事先定义好的数值,如果是多个参数可以使用把json转成string传递过来,接受后把string在转换为json NSLog(@"传递过来的值%@", uniqueIdentifier); } return YES; }
  备注:
[u]复制代码[/u] 代码如下:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000   // 相关spotlight的方法等 #endif // Spotlight支持iOS9以上设备运行,对与低版本的设备需加入这个防止崩溃问题
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部