iOS 9 Search API — Public Indexing in 5 minutes

Charles Vinette
App & Flow
Published in
3 min readSep 18, 2015

The Search API consists of 3 different API’s:

-CoreSpotLight

-NSUserActivity

-Web Markup

This article focuses on the NSUserActivity segment, for public app content discovery.

Here is why it is a big deal:

As you can see in the graph, a major portion of iOS users spend their time surfing the web not in a browser, but in native apps. However, up until now, exploring new content was way easier and convenient on the web, because exploring content of apps wasn’t a possible if it wasn’t installed on the user’s device. The search api fixes that problem. From now on, developers can use NSUserActivity API to index their app content and make it visible to user directly in spotlight, without even having the app installed on the device!

There are 2 kinds of NSUserActivity:

.eligibleForSearch

.eligibleForPublicIndexing

1- NSUserActivity.eligibleForSearch = true

By creating this NSUserActivity and setting this property to true, we are indexing the content shown on the user’s device, locally. Here is how it works

An example of this use would be the following: You booked an apartment on AirBnB that is located in Napa. The AirBnB app indexes the reservation view with its proper properties on your device,like so:

So now, when you search “Napa” in spotlight, since it was indexed with Napa as one of the keywords, spotlight will suggest that content page,in the app, so that you can access it right away.

2- NSUserActivity.eligibleForPublicIndexing = true

By setting this property to true, you flag the content view of this screen as public information. In the previous exemple, the content was only indexed locally. It makes sense, because if I was to search Napa and spotlight suggested your reservation, I wouldn’t be so interested (and you probably wouldn’t be too happy about it). Here is what it would look like in code:

This property is for public content, such as a wikipedia page or an actor’s IMDB page. If the property is true, it will be indexed on the Apple Cloud Index servers, and could eventually be suggested if a user enter relevant keywords like the following example, where the user wants to know more about sprained ankles(99% sure the incomplete word is ankle).

Eventually? What do you mean by eventually? With all the apps available on the app store, the Apple Index Cloud will only start to suggest some content when enough people engaged with it, to make sure it is relevant.

So let’s say I am using a brand new coffee app, I browse multiple coffee shop’s description page to see which one would be the best to work at today. By accessing the description page, I increased the relevancy of the content (only if the content is .enableForPublicIndexing of course). When a certain threshold of relevancy/engagement is met, spotlight will then start to suggest the content.

Once suggested, if the user taps, it will either open the app if it is installed or, if you provided the universal link, it will fire up in Safari, directly on the content’s page and not on the home screen. (Where you should have a nice little banner inviting the user to download the app :) ).

Hopefully the inner working of how the indexing works is a liiiitttlleee bit clearer, this wasn’t meant to be a tutorial or something really technical, I was just wondering how it worked so I looked it up and thought this might be useful to some of you!

Have a good day,

Charles

--

--

Charles Vinette
App & Flow

Founder @AppandFlow. Helping startups increase their chances of success with scalable, high-quality apps, transparent pricing and a startup-friendly process.