iOS 9 SPOTLIGHT
2015-10-16 16:05
405 查看
搜索内容
在苹果发布iOS 9之前,你只能在Spotlight中输入名称来寻找App,而随着苹果发布了一套全新的iOS 9 Search APIs之后,开发者不但可以自由选择App的部分内容编入索引,还能对Spotlight上的搜索结果以及点击不同结果显示的内容进行设置。还可以搜索通讯录中的联系人,信息,网页,App Store,地图。
隐私保护
A private on-device indexEach device contains a private index whose information is never shared with Apple or synced between devices. Only that user can view the item in search results.
每个设备都有自己私有的index,这些内容不与Apple和其他设备共享
Apple’s server-side index.
The server-side index stores only publicly available data that you’ve marked appropriately on your website.
Server端的index只储存用户允许公开的内容
影响index的因素
使用APP的频率。The amount of engagement users have with your content,demonstrated when users tap a search result or find the information。搜索和点击这个搜索结果的用户越多,排名越靠前。
In the case of marked-up web content, the popularity of a URL
and the amount of structured data。越popular的URL排名越靠前。
排名优化建议
Create an app with compelling content。app需要有吸引人的内容。
Improve the relevance of your search results by adopting the
search-related APIs just described.
更好的关联你的搜索结果与搜索相关的APIs
As much as possible, index only the items that users are most likely
只把最可能被用户搜索的内容放入系统的Index中供搜索展示。
Keep the indexes up to date by removing and updating items when necessary。
更新index,删除不需要的内容
Encourage users to engage with an indexed item by providing relevant, rich information about it。
利用联系更紧密和更丰富的内容来吸引用户。
Minimize the time between tapping on a search result and viewing the content in your app。
提升点击搜索结果到APP中展示具体内容的跳转效率。
APIs
NSUserActivityiOS8专为Handoff推出,主要用于在下一个设备继续上一个设备上的工作;
在iOS9之后提升。
Index app items as users perform activities in your app
Mark specific items as available for public searching,
Provide indexable metadata about an item, which gives users rich information in search results
Spotlight可以将activity编入索引,而NSUserActivity就好比网页浏览器的历史堆栈(history stack),使用户能在Spotlight上搜到最近的活动,例如打开在后台的APP,APP显示的页面为之前操作停留的页面.
本地index:
一旦某些内容被记录进 NSUserActivity,就可以在 Spotlight 和 Safari 中同时被搜索到。
云端index:
通过设置 eligibleForSearch 来让这些被 Index 的内容传到 Apple 的云端 Cloud Index 里。云端index:例如打开在后台的APP,APP显示的页面为之前操作停留的页面.
当你让你的user activity有eligibleForPublicIndexing属性时,Apple就开始从用户的搜索结果当中观察这个特殊activity的作用和交互了。如果这个搜索结果是被很多用户所使用的,Apple就提升这个user activity到它自己的云索引(cloud index)中。一旦这个user activity在这个云索引中了,它就可以被所有安装过你的应用的人搜索得到,而不管他们是否有打开过那些内容。这个属性只有当且仅当activities能被你应用的所有用户使用时才能被设置为true。
同时 Apple 也强调了隐私的保护。并不是所有内容都是 Public 的,同一个内容需要在云端被 Index 超过一个限额(具体多少没有公布),才会最后成为 Public 的内容。所以用户不用担心自己看到的内容成为公众都能搜索的内容。
Web markup
Web Markup在网页上显示App的内容并编入Spotlight索引,即便没有安装某个App,苹果的索引器也能在网页上搜索特别的标记(markup),在Safari或Spotlight上显示搜索结果。
Universal links :
用户在打开某个链接,如果他已经装有相对应的 App,会利用 App 中设置过的 Handoff 机制自动打开 App 中的内容。即使他没有装 App,也会顺利的进入 Safari 打开原本应该看到的网站。也是一个通过原本打开网页,而现在可以直接打开 App 的方法,给用户更好的体验,从而提高 App 使用度和曝光度。
它与custom URL是两个不同的概念。
1. Unique:这个link不能与其他app的link相同,因为它是以HTTP或HTTPS标准直接link到你的网页的。
2. Secure:只有这个app的开发者可以创建和上传包含这个links的文件到app相关的web server上。When users install your app, iOS checks a file that you’ve uploaded to your web server to make sure that your website allows your app to open URLs on its behalf , Only you can create and upload this file.
3. Flexible:即使没有安装app,也能通过它打开safari到相应网站
4. Simple:只需要一个URL,在app和网页都能work
5. Private: 其他app不需要check你的app是否安装,也能进行communicate
Apple的建议:
1. 确保APPLE能发现和Index你的网站
最简单的保证Applebot的网页爬虫来crawl你的网站的方法是设置support URL和marketing URL
2. 在你的网站上加用于deep link的markup,用于从网站进入APP
3. enrich your search results by adding markup for structured data.
4. Apple建议加上Smart App Banner
CoreSpotlight
作用 : 提供增、删、改、查等搜过API,可以索引APP的内容
数量限制 : Core Spotlight APIs work best when you have no more than a few thousand items
实现
// 1.导入头文件 #import <CoreSpotlight/CoreSpotlight.h> // 2.初始化 CSSearchableItemAttributeSet CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:@"views"]; // 3.设置attribute属性 title, contentDiscription, thumbnailData, (还可以有:rating, keywords) attributeSet.title = obj; attributeSet.contentDescription=[NSString stringWithFormat:NSLocalizedString(@"open %@", nil),obj]; UIImage *thumbImage = [UIImage imageNamed:[NSString stringWithFormat:@"icon_%@.png",obj]]; attributeSet.thumbnailData = UIImagePNGRepresentation(thumbImage);//beta 1 there is a bug // 4.生成可被搜索的CSSearchableItem ,与attributeSet相关联 CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:obj domainIdentifier:@"com.kdanmobile.CoreSpotlightDemo" attributeSet:attributeSet]; // 5.将CSSearchableItem加到CSSearchableIndex [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:item completionHandler:^(NSError * __nullable error) { if (!error) NSLog(@"%@",error.localizedDescription); }]; // ------------------删除内容 // 1.根据identifiers删除 [[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithIdentifiers:@[identifier] completionHandler:^(NSError * __nullable error) { if (!error) NSLog(@"%@",error.localizedDescription); }]; // 2.根据DomainIdentifiers删除 [[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithDomainIdentifiers:@[domainIdentifier] completionHandler:^(NSError * __nullable error) { }]; // 3.删除全部 [[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:^(NSError * __nullable error) { }]; // ---------------在AppDelegate中响应spotlight搜索结果的点击 - (BOOL)application:(nonnull UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * __nullable))restorationHandler { NSString *idetifier = userActivity.userInfo[@"kCSSearchableItemActivityIdentifier"]; // 根据idetifier做相应的处理 return YES; }
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 搜狗百度360市值齐跌:搜索引擎们陷入集体焦虑?
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 本人即将筹备败家日志,敬请期待!
- IE:使用搜索助手
- C++深度优先搜索的实现方法
- 基于文本的搜索
- php实现搜索一维数组元素并删除二维数组对应元素的方法
- 使用Sphinx对索引进行搜索
- asp 多关键词搜索的简单实现方法
- C#使用foreach语句搜索数组元素的方法
- JavaScript中数组的排序、乱序和搜索实现代码
- C#编程实现Excel文档中搜索文本内容的方法及思路
- sqlserver中在指定数据库的所有表的所有列中搜索给定的值
- 可以用来搜索当前页面内容的js代码