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搜索相关推荐

  1. alfred 常用搜索_如何使用Alfred完善macOS的Spotlight搜索

    alfred 常用搜索 Spotlight Search on macOS has gotten a lot better over the last few years, but there's s ...

  2. 你应该知道的Spotlight搜索快捷键

    转自:http://www.macx.cn/thread-2039527-1-1.html Spotlight是Mac OS X中功能非常强大的内置搜索引擎,通过Spotlight我们不仅可以找到任何 ...

  3. 在Mac OS X上利用Spotlight搜索代码

    2019独角兽企业重金招聘Python工程师标准>>> 用grep来搜代码和方便,最原生态了,常用的: ➜ ~ grep 'NuPlayer' -iInr --color ./aos ...

  4. 解决Mac上用spotlight搜索输入几个字母后闪退

    问题描述:使用spotlight进行搜索时,只要输入字母超过一定个数(在我的Mac上是3个),spotlight就闪退了. 谷歌搜索得到大部分解决方案是在系统自带词典的偏好设置里取消外部字典的勾选(如 ...

  5. Mac上用spotlight搜索输入几个字母后闪退

    最近使用电脑时遇到的问题: 使用spotlight进行搜索时,只要输入字母超过一定个数(在我的Mac上是3个),spotlight就闪退了. 谷歌搜索得到大部分解决方案是在系统自带词典的偏好设置里取消 ...

  6. [Swift]LeetCode74. 搜索二维矩阵 | Search a 2D Matrix

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  7. iOS开发之集成iOS9中的Core Spotlight Framework搜索App的内容

    转载自:  http://www.cnblogs.com/ludashi/p/4867511.html iOS开发之集成iOS9中的Core Spotlight Framework搜索App的内容 S ...

  8. 禁用 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 ...

  9. 微信sdk swift版_使用Swift 4的iOS版Google Maps SDK终极指南

    微信sdk swift版 by Dejan Atanasov 通过Dejan Atanasov 使用Swift 4的iOS版Google Maps SDK终极指南 (Your ultimate gui ...

  10. 如何使用iOS9中的Core Spotlight框架

    如何使用iOS9中的Core Spotlight框架 作者: Gabriel Theodoropoulos,时间:2015/12/22 翻译:BigNerdCoding, 如有错误欢迎指出.原文链接 ...

最新文章

  1. Linux内存管理Linux Memory Management Notes
  2. python一些小操作
  3. php7序列化,php 7.2中未序列化字符串时出现问题
  4. ubuntu安装与配置mysql_ubuntu下mysql的安装与配置
  5. [包计划] node-fs-extra
  6. 数据结构树4-二叉搜索树2
  7. 2021年低碳科技白皮书
  8. imos style android,自定义的第一个view
  9. gridview 默认编辑按钮改成图片
  10. eclipse菜单解释及中英对照《二》
  11. Linux+Apache+Mysql+PHP典型配置
  12. 推荐几个我目前在用的简历制作工具
  13. iOS tabbar 控制器基本使用
  14. Codeforces1575 D. Divisible by Twenty-Five(dp)
  15. kubeadm工作原理-kubeadm init原理分析-kubeadm join原理分析
  16. 20多个可以提高你安卓开发技能的开源app
  17. linux lds,Linux LDS 文件格式详细分析.pdf
  18. 《精益软件度量——实践者的观察与思考》—第1章1.2节度量是什么
  19. 中台:业务中台、数据中台、技术中台
  20. php取am+pm时间格式,php – 如何将带有日期和时间AM / PM的字符串转换为24小时的mysql时间戳格式...

热门文章

  1. Redis RDB和AOF
  2. MyBatis之one2one与one2many
  3. sleep、yield、join方法简介与用法 sleep与wait区别 多线程中篇(十五)
  4. 扭曲丛林服务器未响应,LOL等级最高玩家已246级 狂刷扭曲丛林攒经验
  5. 各种 Python 库/模块/工具
  6. 431 Request Header Fields Too Large
  7. Gin:路由抽离与分组
  8. 5393: YuYu的密码II
  9. C#实现让鼠标点击任意绝对位置
  10. JWT解析及安全问题