Chapter 13.  Displaying Contents of your App in Spotlight

Many users of Mac OS and iOS love one feature in particular: Spotlight search. Spotlight keeps an index of all files, contacts, contents, and more on your Mac, and it's been in iOS too for a while now. With iOS 9, Apple made it possible for developers to index the contents of their own apps, enabling users to discover app contents right from the Spotlight search they know and love.

Ever since, iOS 9 Apple has been pushing to make Spotlight better, more relevant, more present, and more helpful to users. In this chapter, we'll explore what Spotlight can do for your apps and how you can make use of the CoreSpotlight APIs to provide your users with an amazing search experience that will benefit your users and drive traffic to your own apps.

We'll start off with an overview of Spotlight, what it is and why you want your app to show up in the Spotlight search results. Next, we'll take a look at the various ways that Apple enables developers to index contents. We'll wrap up this subject by exploring the best practices that you should adopt when you add your app to Spotlight.

In this chapter, the following topics are covered:

  • Understanding Spotlight search
  • Adding your app contents to the Spotlight index
  • Handling search result selection
  • Adhering to Spotlight best practices

By the end of this chapter, you will know everything you need to know about Spotlight and how you can optimally implement it to provide your users with the best search results possible for your app.

Understanding Spotlight search

If you have a Mac, which you most likely do, you will have probably used the blazing fast Spotlight search feature on it. Furthermore, if you loved this feature on your Mac, you probably use it on iOS as well. Spotlight is a highly optimized search engine that enables you to find content throughout your device.

Spotlight has been around since iOS 3. However, it wasn't until iOS 9 that Apple opened up Spotlight to developers. This means that starting with iOS 9, Spotlight indexes everything from web results, apps, app store results, and any content you add to the Spotlight index yourself. Results are presented with an image, a title, and some extra information, and sometimes, extra buttons are added to make a phone call or to start turn-by-turn navigation to an address.

The results that Spotlight displays are a mix of public or online contents and private results. If your app has indexed items that are publicly available, Apple will make them visible to all users who have your app installed for as long as enough people actually interact with this particular searchable item.

A great example of public content for almost any app are the main navigation items in your app. Imagine you have an app that has a couple of tabs in a UITabBar. Any user who downloads your app and opens it can immediately access each tab if they want to. This means that these tabs are basically public; any user of your app can access these tabs.

Your app can index these tabs using CoreSpotlight and mark them as publicly available. This will not immediately push these items to all users. What happens behind the scenes is that CoreSpotlight actually indexes this item as it normally would, and whenever a user selects this particular item from a list of Spotlight search results, an irreversible hash of the item is sent to Apple's servers.

If Apple receives the same hash over and over again, a certain threshold will be reached. Once this threshold is reached, the indexed item is sent to Apple's servers and it's pushed to all people who have your app installed. If your indexed item has a public web resource associated with it, your public searchable item will even be shown to people who don't have your app installed.

The public results threshold is actually a great feature that protects you and your users in several ways. Imagine that any app developer could mark any piece of content as public. Every time a developer does this, the item is immediately pushed to all users. This would pollute Spotlight, and the entire feature would become essentially worthless. Spotlight's goal is to provide relevant and interesting results. The threshold for interactions makes sure that enough people consider the displayed item to be appropriate for their search query, which means that bad indexing or spam doesn't have a chance to thrive.

Another reason this threshold exists is to protect your user's data. It's perfectly fine to add personal and private data to Spotlight. The standard mail app does this so users can search their e-mail messages using Spotlight. Obviously, these e-mail messages should not be publicly indexed so they shouldn't be marked as such. Mistakes happen though, and in case you do end up marking a private data as public by accident, there is no way this specific item will show up for other users because the public result threshold for the item will never be reached since only one user interacts with the Spotlight search result.

It goes without saying that great Spotlight visibility can really boost usage of your apps, especially since users don't even need to have your app installed to see results for your app as long as there is a web resource available for your indexed contents. Apple has worked really hard to ensure that Spotlight is fast and provides a seamless experience to your users. This means that users won't notice whether a result comes straight from their own device or if a result is shown because it was publicly indexed.

You might have noticed that Safari sometimes shows results for in-app content. These results come from Spotlight. Whenever you add a web resource to an item you index, Safari will show this resource if it matches a user's query in the search bar. In this chapter, you will learn all about optimally indexing your app's contents; so, if you have an app that has a website that mirrors its contents, you'll know how to maximize your presence in search results for both Spotlight and Safari.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.42.196