【Swift】SpotLight搜索
SpotLight主要功能是在iOS9系统界面下拉会出现搜索功能界面,在这里可以搜索关键信息,来展示应用内的内容,并且点击信息打开应用跳转具体页面等操作。这个功能还是很有用的,面对这越来越多的应用霸占你手机,给你的应用加上这么一个搜搜功能,还是有点与众不同,主要是提升逼格。
1、导入头文件
import CoreSpotlight
import MobileCoreServices
2、设置应用内搜索
func indexItem(title: String, desc: String, identifier: String) {let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)attributeSet.title = titleattributeSet.contentDescription = descattributeSet.keywords = ["abc","cd","efg"]let item = CSSearchableItem(uniqueIdentifier: "\(identifier)", domainIdentifier: "Lingye.OopsVoice", attributeSet: attributeSet)CSSearchableIndex.default().indexSearchableItems([item]) { error inif let error = error {print("Indexing error: \(error.localizedDescription)")} else {print("Search item successfully indexed!")}}}func deindexItem(identifier: String) {CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: ["\(identifier)"]) { error inif let error = error {print("Deindexing error: \(error.localizedDescription)")} else {print("Search item successfully removed!")}}}
3、在Appdelegate中实现SpotLight搜索
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {if userActivity.activityType == CSSearchableItemActionType {if let uniqueIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String {deindexItem(identifier: uniqueIdentifier)}}return true}
【Swift】SpotLight搜索相关推荐
- alfred 常用搜索_如何使用Alfred完善macOS的Spotlight搜索
alfred 常用搜索 Spotlight Search on macOS has gotten a lot better over the last few years, but there's s ...
- 你应该知道的Spotlight搜索快捷键
转自:http://www.macx.cn/thread-2039527-1-1.html Spotlight是Mac OS X中功能非常强大的内置搜索引擎,通过Spotlight我们不仅可以找到任何 ...
- 在Mac OS X上利用Spotlight搜索代码
2019独角兽企业重金招聘Python工程师标准>>> 用grep来搜代码和方便,最原生态了,常用的: ➜ ~ grep 'NuPlayer' -iInr --color ./aos ...
- 解决Mac上用spotlight搜索输入几个字母后闪退
问题描述:使用spotlight进行搜索时,只要输入字母超过一定个数(在我的Mac上是3个),spotlight就闪退了. 谷歌搜索得到大部分解决方案是在系统自带词典的偏好设置里取消外部字典的勾选(如 ...
- Mac上用spotlight搜索输入几个字母后闪退
最近使用电脑时遇到的问题: 使用spotlight进行搜索时,只要输入字母超过一定个数(在我的Mac上是3个),spotlight就闪退了. 谷歌搜索得到大部分解决方案是在系统自带词典的偏好设置里取消 ...
- [Swift]LeetCode74. 搜索二维矩阵 | Search a 2D Matrix
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- iOS开发之集成iOS9中的Core Spotlight Framework搜索App的内容
转载自: http://www.cnblogs.com/ludashi/p/4867511.html iOS开发之集成iOS9中的Core Spotlight Framework搜索App的内容 S ...
- 禁用 spotlight_如何在Mac,iPhone和iPad上禁用Spotlight的Web搜索
禁用 spotlight Apple's Mac OS X and iOS send your Spotlight searches over the Internet to Apple. You t ...
- 微信sdk swift版_使用Swift 4的iOS版Google Maps SDK终极指南
微信sdk swift版 by Dejan Atanasov 通过Dejan Atanasov 使用Swift 4的iOS版Google Maps SDK终极指南 (Your ultimate gui ...
- 如何使用iOS9中的Core Spotlight框架
如何使用iOS9中的Core Spotlight框架 作者: Gabriel Theodoropoulos,时间:2015/12/22 翻译:BigNerdCoding, 如有错误欢迎指出.原文链接 ...
最新文章
- Linux内存管理Linux Memory Management Notes
- python一些小操作
- php7序列化,php 7.2中未序列化字符串时出现问题
- ubuntu安装与配置mysql_ubuntu下mysql的安装与配置
- [包计划] node-fs-extra
- 数据结构树4-二叉搜索树2
- 2021年低碳科技白皮书
- imos style android,自定义的第一个view
- gridview 默认编辑按钮改成图片
- eclipse菜单解释及中英对照《二》
- Linux+Apache+Mysql+PHP典型配置
- 推荐几个我目前在用的简历制作工具
- iOS tabbar 控制器基本使用
- Codeforces1575 D. Divisible by Twenty-Five(dp)
- kubeadm工作原理-kubeadm init原理分析-kubeadm join原理分析
- 20多个可以提高你安卓开发技能的开源app
- linux lds,Linux LDS 文件格式详细分析.pdf
- 《精益软件度量——实践者的观察与思考》—第1章1.2节度量是什么
- 中台:业务中台、数据中台、技术中台
- php取am+pm时间格式,php – 如何将带有日期和时间AM / PM的字符串转换为24小时的mysql时间戳格式...