81
Search APIs & Universal Links Mercari Inc. @kitasuke

Search APIs & Universal Links

Embed Size (px)

Citation preview

Page 1: Search APIs & Universal Links

Search APIs & Universal LinksMercari Inc.

@kitasuke

Page 2: Search APIs & Universal Links

About me

Page 3: Search APIs & Universal Links

Mercari

Page 4: Search APIs & Universal Links

My works

→ Cardio -Simple HealthKit wrapper for workout app in watchOS 2-

→ PagingMenuController -Paging view controller with customizable menu-

→ GoogleMaterialIconFont -Google Material Design Icons for Swift and ObjC-

Page 5: Search APIs & Universal Links

My future talks

→ Introducing new features for watchOS 2@MOSA software meeting

Page 6: Search APIs & Universal Links

Search API

Page 7: Search APIs & Universal Links

Completely New Search Experience

Page 8: Search APIs & Universal Links

App results appear in Spotlight and Safari even

app not installed

Page 9: Search APIs & Universal Links
Page 10: Search APIs & Universal Links

Rich contents with powerful action

Page 11: Search APIs & Universal Links
Page 12: Search APIs & Universal Links

Universal and Seamless experience

Page 13: Search APIs & Universal Links
Page 14: Search APIs & Universal Links

How it works

Page 15: Search APIs & Universal Links

Index contents via Search APIs

Page 16: Search APIs & Universal Links

What to index?

Page 17: Search APIs & Universal Links

Index Architecture

Page 18: Search APIs & Universal Links

On-Device index

Page 19: Search APIs & Universal Links

Apple's cloud index

Page 20: Search APIs & Universal Links

Let's see in-depth features!

Page 21: Search APIs & Universal Links

3 Search APIs

Page 22: Search APIs & Universal Links
Page 23: Search APIs & Universal Links

NSUserActivity

Page 24: Search APIs & Universal Links

App Search

→ Activities can be designated as searchable→ Add indexable metadata

→ Results in Spotlight and Safari→ Revisit activity on Search selection

Page 25: Search APIs & Universal Links

Enable Capabilities

var eligibleForHandoff: Boolvar eligibleForSearch: Boolvar eligibleForPublicIndexing: Bool

Page 26: Search APIs & Universal Links

Provide Attributes and Keywords

var title: String?var keywords: Set<String>var contentAttributeSet: CSSearchableItemAttributeSet?var expirationDate: NSDate

Page 27: Search APIs & Universal Links

Restoring on the Web

var webpageURL: NSURL?

Page 28: Search APIs & Universal Links

Create Activity

var activity: NSUserActivity = NSUserActivity(activityType: "com.example")

activity.title = "Baked Potato Chips"activity.userInfo = ["id": "http://www.example.com/recipe/111"]

activity.eligibleForSearch = trueactivity.eligibleForPublicIndexing = trueactivity.becomeCurrent()

Page 29: Search APIs & Universal Links
Page 30: Search APIs & Universal Links

Continue Activity

func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == "com.example" { // Restore state for userActivity and userInfo } return true}

Page 31: Search APIs & Universal Links

Public Indexing

→ Activities can be designated as public→ Multiple users engage with device results

→ Popular public results available to other users→ Results in Search and Safari (if URL included)

Page 32: Search APIs & Universal Links

Public vs Private

→ Designated "public" if searchable activity fields are solely public

→ Provisions to prevent user-specific activities from being indexed

Page 33: Search APIs & Universal Links

Additional Benefits

Page 34: Search APIs & Universal Links

Handoff

Page 35: Search APIs & Universal Links

Siri suggestions

Page 36: Search APIs & Universal Links

CoreSpotlight

Page 37: Search APIs & Universal Links

CoreSpotlight

→ For any app content→ Methods to add, update and delete items→ Used by Messages, Mail, Calendar and Notes

Page 38: Search APIs & Universal Links
Page 39: Search APIs & Universal Links

Create item// Create attributeSet and populate with metadatalet attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)

attributeSet.title = "Haleakala Sunrise"attributeSet.contentDescription = "May 12, 2015 Maui, Hawaii"

// Create item with unique identifier, domainIdentifier used to group itemslet item = CSSearchableItem(UniqueIdentifier: "1", domainIdentifier: "album-1", attributeSet: attributeSet)

Page 40: Search APIs & Universal Links

Index item

// Index itemCSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { error in if error != nil { print("Item indexed!") }}

Page 41: Search APIs & Universal Links

Restore

// Application delegate called when CoreSpotlight result is tappedfunc application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == CSSearchableItemActionType { let uniqueIdentifier = userActivity.userInfo? [CSSearchableItemActivityIdentifier] as? String // Use 'uniqueIdentifier' } return true }

Page 42: Search APIs & Universal Links

Update

// Same method as adding item to indexfunc indexSearchableItems(items: [CSSearchableItem], completionHandler: ((NSError?) -> Void)?)

Page 43: Search APIs & Universal Links

Delete

// Identifiersfunc deleteSearchableItemsWithIdentifiers(identifiers: [String], completionHandler: ((NSError?) -> Void)?)

identifiers = ["1", "4", "5"]

Page 44: Search APIs & Universal Links

Delete

// DomainIdentifierfunc deleteSearchableItemsWithDomainIdentifiers(DomainIdentifiers: [String], completionHandler: ((NSError?) -> Void)?)

domainIdentifiers = ["domain-2"]

Page 45: Search APIs & Universal Links

Delete// Allfunc deleteAllSearchableItemsWithCompletionHandler(completionHandler: ((NSError?) -> Void)?)

Page 46: Search APIs & Universal Links

Web Markup

Page 47: Search APIs & Universal Links

Indexing Web Content

→ The content driving your app may live on the web, not locally inside the app

→ Deep linked pages from your app's website are indexed for app search

Page 48: Search APIs & Universal Links

Applebot finds deep links from the web

Page 49: Search APIs & Universal Links
Page 50: Search APIs & Universal Links

Enabling app search

1. Allow Apple to discover and index your app's website

2. Ensure your app's website contains markup for mobile deep links

3. Enable deep link handling for your app4. Add markup for structured data (optional, but

highly recommended)

Page 51: Search APIs & Universal Links
Page 52: Search APIs & Universal Links

Smart App Bannersif app is not installed, Safari prompts the user

<meta name="myApp" content="app-id=123, app-argument=https://example.com/about affiliate-date=optionalAffiliateData">

app-argument is passed to application(_:openURL:sourceApplication:annotation:), and is

also used to index your app

Page 53: Search APIs & Universal Links

Deep Linking

→ Universal linkhttps://developer.apple.com/videos/wwdc/2014/?

include=101#101→ Custom URL scheme

apple://wwdc/2014/?include=101#101

Page 54: Search APIs & Universal Links

Universal links advantages

→ Unique→ Secure→ Flexible

→ Work seamlessly across app and website

Page 55: Search APIs & Universal Links

Support Universal Link in your server

→ Create your apple-app-site-association file→ Generate an SSL certification

→ Sign your file→ Upload to your server

Page 56: Search APIs & Universal Links

Support Universal Link in your app

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool

var webpageURL: NSURL?var activityType: Stringlet NSUserActivityTypeBrowsingWeb: Stringclass NSURLComponents: NSObject

Page 57: Search APIs & Universal Links

Configure your associated domains

Page 58: Search APIs & Universal Links

Other deep link schemesTwitter Cards

<meta name="twitter:app:name:iphone" content="myAppName"><meta name="twitter:app:id:iphone" content="myAppID"><meta name="twitter:app:url:iphone" content="myURL">

Facebook's App Links

<meta name="al:ios:app_name" content="myAppName"><meta name="al:ios:app_store_id" content="myAppID"><meta name="al:ios:url" content="myURL">

Page 59: Search APIs & Universal Links

Support deep linking

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { // In this example, the URL is http://example.com/profile/?123 guard let component = NSURLComponents(URL: url, resolvingAgainstBaseURL: true), let path = component.path, let query = component.query else { return false }

if path == "/profile" { // Pass the profile ID from the URL, to the view controller return profileViewController.loadProfile(query) } return false}

Page 60: Search APIs & Universal Links

Rich Results

→ Go beyond just a title and description→ Results can contain images, structured data, and

even actions→ Rich results are more engaging to users and can

improve your ranking

Page 61: Search APIs & Universal Links

Other deep link schemesOpen Graph

<meta property="og:image" content="http://example.com/hello.jpg"><meta property="og:audio" content="http://example.com/music.m4a"><meta property="og:video" content="http://example.com/cats.mp4">

schema.org JSON-LD

<script type="application/ld+json">{ "@context": "http://schema.org", "@type": "AggregateRating", "ratingValue": "4", "reviewCount": "250"}</script>

Page 62: Search APIs & Universal Links
Page 63: Search APIs & Universal Links

Supported schemas

→ AggregateRating→ Offers

→ PriceRange→ InteractionCount→ Organization

→ Recipe

Page 64: Search APIs & Universal Links

App Search API Validation Tool

Test your webpage for iOS 9 Search APIs. Enter a URL and Applebot will crawl your webpage and show

how you can optimize for best results.https://search.developer.apple.com/appsearch-

validation-tool/

Page 65: Search APIs & Universal Links

Improve Ranking

Page 66: Search APIs & Universal Links

Relevance

Page 67: Search APIs & Universal Links

Linking 3 APIs

Page 68: Search APIs & Universal Links

Linking 2 APIs

Page 69: Search APIs & Universal Links

Relevance score

Page 70: Search APIs & Universal Links

User Experience

Page 71: Search APIs & Universal Links

Descriptive Results

Page 72: Search APIs & Universal Links

Richer results have better satisfaction and engagement

→ Thumbnail, well-structured description, ratings, and actions

→ Relevant and applealing image→ Key information user is looking for

Page 73: Search APIs & Universal Links

Keywords associate your result with queries

→ Typical items should have 3 to 5 keywords→ Category keywords, e.g., "ticket" or "recipe"→ Synonyms or abbreviations for item subject

Page 74: Search APIs & Universal Links

UI Behavior on App Launch

Page 75: Search APIs & Universal Links

Speed

Time from tapping a search result to the content in your app is measured and used in ranking.

Page 76: Search APIs & Universal Links

Data protection

Pay attention to the appropriate data protection level for your user's content.

Page 77: Search APIs & Universal Links

Common FAQs

Page 78: Search APIs & Universal Links

Not showing in the search results

→ Try using different keywords→ In the case of Web Markup, results will only show

up after the page has been crawled by Applebot, and once a certain level of relevance has been

attained

Page 79: Search APIs & Universal Links

Supported devices?

App Search is available with iOS9, However, the search functionality of NSUserActivity and

CoreSpotlight are not supported on the iPhone 4s, iPad 2, iPad (3rd generation), iPad mini, and iPod

touch (5th generation).

Page 80: Search APIs & Universal Links

Available on OS X?

CoreSpotlight and the search functionality of NSUserActivity are not supported. However, web

search results may be shown.