Chapter 13. Web and Search
iOS brings with it some really exciting functionality, such as indexing content inside your app as searchable content on an iOS device. Even better, you can contribute to iOS’s public search index so that your searchable content appears on devices that don’t even have your app installed. That’s pretty cool, don’t you agree? In this chapter, we’ll have a look at all these great features.
13.1 Continuing a Spotlight Search Within Your App
Problem
You are already indexing your app content in Spotlight (more recipes on that in this chapter), but you also want to allow the user to continue the search from Spotlight directly in your app (see Figure 13-1).
Solution
Follow these steps:
- Add the
CoreSpotlightContinuation
key to your Info.plist file with a Boolean value ofYES
. This will allow your app to take part in Spotlight search continuation. - Index your searchable items, as you will learn in Recipe 13.2.
- Implement the
application(_:willContinueUserActivityWithType:)
method of your app delegate. - In this method, see whether the given activity type is
CSQueryContinuationActionType
. If yes, returntrue
; otherwise, returnfalse
(or, if you have other activity types to process, look at those as well before returningfalse
). - Implement the
application(_:continue:restorationHandler:) ...
Get iOS 11 Swift Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.