Apple Search and iOS 9

Search Improvements
iOS 9 now makes it easy for users to discover information in apps by surfacing the content of the apps and websites in Search on iOS 9.
(with seamless universal linking, this takes users to the best place to view the results.)

App history
Deep links make it easy for users to get back to where they were in your app—just indicate that your app is eligible for Search and iOS 9 will create them for you.

Content indexing
Help users find relevant information within your app by using Core Spotlight to add it to the iOS 9 Search index.

Web markup
You can now indicate items on your website that can be accessed from your app and make those available to Search. iOS 9 also supports flexible universal links that seamlessly take users back to your website or directly into your app if it’s installed.

What is Deep Linking in iOS 9?

Deep linking is a way for app developers to communicate what content can be found within their apps and a way to specifically trigger links and actions to specific pages or sections of their app. Apple claims you will see an “increase the usage of your app” and more importantly “improve its discoverability by displaying your content when users search across the system and on the web.” For example, searching for “potatoes” yields recipes from several apps, taking users directly to the recipe page. Apple’s embrace of deep linking will also boost Google and Facebook’s similar initiatives.

What has changed?
The changes will allow users to jump from app to app more naturally, as well as blurring the division between local apps and web-based content (& reduce the amount of time you spend entering login credentials). Meanwhile, content within apps can show up within iOS 9’s newly-supercharged search.

How to implement Deep Linking?

There are essentially 4 areas:

  1. Make App Activities and States Searchable – Use NSUserActivity APIs
  2. Make App Content Searchable – Use Core Spotlight APIs
  3. Make App Content Searchable – Use Web Markup
  4. Universal Links – Connect App & Web Pages

1) Make App Activities and States Searchable

Method: use NSUserActivity to mark specific ‘activities’ or ‘app states’ as searchable.
Functionality: When a searchable activity or app state appears in Search or Safari results, users can tap the result to return to the relevant area in your app.
Benefits: NSUserActivity introduces properties you can use to provide indexable metadata about an activity or state, this helps provide rich information in the search results.
For example, you can specify a title, description, and thumbnail image for a result.
Implementation: To make an app activity or state searchable, create an NSUserActivity object to represent it. Use NSUserActivity properties to fully describe the activity or state and to make it eligible for search.

Create a new activity – When a user performs the activity or enters the app state associated with the NSUserActivity object you created, your app calls [userActivity becomeCurrent] to mark the activity as current. A current activity that’s eligible for search is automatically added to the universal index (that is, CSSearchableIndex). [code language=”html”] // It’s recommended that you use reverse DNS notation for the required activity type property. var activity:NSUserActivity = NSUserAcivity(activityType: "com.myCompany.myContentType")

// Set properties that describe the activity and that can be used in search. activity.title = "My Activity Title" activity.userInfo = ["id": "http://www.mydomain.com/myContentItem/ABC-123"]

// Add the item to the private on-device index. activity.eligibleForSearch = true [/code]

Continuing an activity – When a user taps on a result that’s associated with an activity or state, your app uses NSUserActivity APIs to continue the activity and restore the user’s position.

[code language=”html”] func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == "com.myCompany.myContentType" { // Restore app state for this userActivity and associated userInfo value. } return true } [/code]

NOTE – An activity that’s marked public can be shown to other users and can help encourage them to use your app. By default, activities are private.

You should designate an activity as public only when the activity might be useful for other users.
In general, user-created content is never useful for public results.
To mark an activity as public, set the eligibleForPublicIndexing property to YES.

2) How to add Core Spotlight to index your app content

Method: iOS 9 allows apps to communicate bidirectionally with Spotlight, the iOS system-wide search feature.
iOS 9 apps can ask for their content to be shown in the Spotlight search results.
Functionality: If a user taps one of these Spotlight search results, the app gets launched and told what was tapped so it can load the correct content. See example
Benefits: Core Spotlight provides a database-like API that lets you add, retrieve, update, and delete items that represent searchable app content. When you use Core Spotlight to index items, you make it easy for users to search their own content.
Implementation: To make content searchable, first create an attribute set that contains properties that specify the metadata you want to display about an item in a search result. Below is a breakdown of the features and code usage:

Creating an attribute set for a searchable item Create a CSSearchableItemAttributeSet object and set its properties. See Listing 3

Create an object to represent the item and add it to the index Create a CSSearchableItem object to represent the item and add it to the index. See Listing 4

Implementing continueUserActivity in the app delegate When users tap a search result for an item that you added to the index, your app should open and restore the context associated with that item. To accomplish this, your app delegate implements application:continueUserActivity:restorationHandler:, checking the type of the incoming activity to see if the app is opening because the user tapped an indexed item in a search result. See Listing 5

Relate a user activity and a searchable item It’s recommended that you adopt both NSUserActivity and Core Spotlight functionality if your app lets users create or store content. Adopting both APIs lets you create relationships between activities and items that represent the same thing, which improves the user’s experience. See Listing 6

Batch Updates to the Index Be sure to set the indexDelegate property in your app and implement the required CSSearchableIndexDelegate methods. See Listing 7

Set crash handling Using clientState to help you handle a crash while batching. See Listing 8

Removing items from the index Core Spotlight defines a few ways you can remove data from the index. See Listing 9

Create an index-maintenance app extension You should update the index while your app is running, but you can also create an index-maintenance app extension that lets the system communicate with your app while it’s not running. See Listing 10

3) Make App Content Searchable with Web Markup

Apple indexes web content and makes it available in Search and Safari so you need to add markup to help Apple discover & index your content & display rich results. If you mirror your app content on a website (or your app gets all its content from a website), you can use web markup to give users access to your app content in Search results. Apple allows developers to add advertising banners (called Smart App Banners) to promote your app directly on a website. Adopting Smart App Banners is the best way to help users of your website discover your app.

Including an app-argument in your Smart App Banner markup allows Apple to index your content.

What are Smart App Banners?
Smart App Banners provide a way of promoting apps when viewed in mobile Safari. Presented as a fairly unobtrusive banner at the top of webpages they show details of the app, it’s icon, ratings and price information. If the app is already installed on the device the ‘view’ button says ‘open’ and clicking on the banner launches the app. If the app isn’t installed clicking the banner launches the app store, taking the user to the app download page.
smart app banner
Features-

  • They only show on the Safari browser on iOS devices.
  • They only display on devices that support the promoted app. (If your app is only compatible with iOS 7 and above then a user on an iOS 6 device will never see the banner – likewise, a banner for an iPad-only app will not display on an iPhone or iPod.)
  • If an app isn’t available in the user’s country, the Smart App Banner will not display.
  • Smart App Banners detect whether the user already has the featured app. If not, the Smart App Banner invites the user to download or purchase the app, and tapping View brings the user to your App Store page.

How to implement?

  1. Add a meta tag to the head of your website that has an ‘app-argument’ tag.
  2. In your app, use the ‘application:openURL:sourceApplication:annotation:’ method.

See Smart App Banners Tutorial or Smart App Banners What Are They

WEBSITE – Add the following meta tag to the head of your website. Include the parameter tag ‘app-argument’ (this needs to be a full URL)

[code language=”html”] <meta name="apple-itunes-app" content="app-id=myAppStoreID, app-argument=myURL"/> [/code]

APP – In the app, use ‘application:openURL:sourceApplication:annotation:’ method in the app delegate which runs on launch. The app-argument parameter is available as the NSURL url object. [code language=”html”]-(BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation[/code]

Alternative to Smart App Banners
As an alternative to using Smart App Banners to describe deep links on your website, you can use one of the open standards Apple supports. Use standards-based markup for structured data such as Schema.org to annotate your web content so that users can see rich search results. For example, a recipe website might use the markup shown below to provide richer information about a recipe. In addition to using structured data markup from Schema.org, you can provide Open Graph markup for specifying an image, or preferred title and description to accompany the result.

4) Setup Universal Links to Connect App & Web

Method: In iOS 9, your app can register to open web links (using https or http) directly, bypassing Safari.

This connection between your app and website helps Apple surface your app content in search results.

Functionality: After you place the signed JSON file on your website and your app adds the entitlement, when a user taps on a link to your website, your app opens to handle the link. Support for these universal links is built on the same mechanism that powers Handoff between a web browser and a native app, and shared web credentials. A trust relationship between the app and the website is established by adding a com.apple.developer.associated-domains entitlement to your app and an apple-app-site-association file to your website.
(See Web Browser–to–Native App Handoff and Shared Web Credentials Reference)

Implementation:

STEP 1 – In your com.apple.developer.associated-domains entitlement, include a list of all the domains your app wants to handle as universal links.

[code language=”html”] applinks:developer.apple.com [/code]

STEP 2 – In your apple-app-site-association file, you can specify which paths from your website should be handled as universal links.

[code language=”html”] { "applinks": { "apps": [], "details": { "9JA89QQLNQ.com.apple.wwdc": { "paths": [ "/wwdc/news/", "/videos/wwdc/2015/*" ] } } } }

[/code]

To receive the link and handle it in within your app, you need to adopt the UIApplicationDelegate methods for Handoff (specifically application:continueUserActivity:restorationHandler:).

Adopting universal links in your app is strongly recommended over the use of custom URL schemes. Benefits of adopting universal links include:

Advantages

  • It avoids the privacy issues. Since use of the custom schemes doesn’t tell the originating app whether or not you have the destination app installed.
  • links always open in the correct app, which isn’t true of URL schemes since any app can technically adopt them, resulting in conflict if more than one select the same.
  • Maintains a solid failure path which doesn’t result in a user encountering nothing at all when an app isn’t installed (the URL will direct them to an app’s companion website in Safari, either to the relevant content, or, so long as a developer sets one up, to a destination page that can prompt an app install).
  • They use standard http or https web links, and let you specify how much of your site can be found in your app, and what to do when content isn’t actually in your app yet (they can still find it on the web, and when you do add it, they’ll automatically be redirected to the app).

How to set up Universal Links?
To successfully route users who click on links and send them to your app you need to create a special json file that resides on your website’s server. (In iOS 9, Apple makes the process easier by removing the requirement that this file be signed using an SSL certificate from an outside provider.)

What about older apps?
There is a hard 50 URL scheme limit on apps submitted prior to iOS 9 that’s generated automatically though usage, after which using them will result in a failure without any indication of what’s gone wrong.
NOTE – You do not need a web version counterpart like you currently do with Google’s App Indexing protocol. Deep linking can get results for your app even when a user doesn’t have your app installed.
Search landscape now has Google’s app indexing, Bing’s app linking and Facebook’s app links + Apple’s Deep Links.

Conclusion –
App Search in iOS 9 gives users great new ways to access information inside of your app, even when it isn’t installed. When you adopt iOS 9 Search, users can access activities and content deep within your app through Handoff, Siri Reminders, and Search results.

In addition to improving the user experience, adopting Search helps you increase the usage of your app and improve its discoverability by displaying your content when users search across the system and on the web.

Developer Notes & Links Overview

Official Apple Developer Documentation:
The detailed protocol for implementing these parameters into your apps: https://developer.apple.com/library/prerelease/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS9.html#//apple_ref/doc/uid/TP40016198-DontLinkElementID_1

NOTE – The three Search-related APIs are designed to work in concert. If you mirror app content on the web, you can adopt all three; apps that don’t have related content on the web can adopt NSUserActivity and the Core Spotlight APIs.

SOURCES –

Author:

Share Button