User spends more time on apps than web
NSUserActivity
used primary in Handoff which introduced in iOS 8.
In iOS 9, activities can be designed as searchable.
Steps to add into on-device index
NSUserActivity
the following properties are only available in iOS 9
setting eligibleForHandoff
to true
that allows that activity can be continues via Hand off
setting eligibleForSearch
to true
that allows that activity can be as a result in Spotlight
setting keywords
with keywords for helping the search
setting contentAttrivuteSet
for information appearing in search result
setting expirationDate
for the date of expiring any content when the content is not valid in after the expiration date.
setting webpageURL
for restoration to a web page
var activity: NSUserActivity = NSUserActivity(activityType:"com.myApp.myActivity")
activity.title = "activity title"
activity.userInfo = ["id": "1234"]
activity.eligibleForSearch = true
activity.becomeCurrent()
the search result
func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool {
//handle the activity
if userActivity.activityType == "com.myApp.myActivity" {
}
return true
}
var activity: NSUserActivity = NSUserActivity(activityType:"com.myApp.myActivity")
activity.title = "activity title"
activity.userInfo = ["id": "1234"]
activity.eligibleForSearch = true
//setting the public indexing as true
activity.eligibleForPublicIndexing = true
activity.becomeCurrent()
Steps to create
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUUTypeImage as String)
attributeSet.title = "Sunrise"
attributeSet.contentDescription = "Nice Sunrise on May 12, 2015"
//Create item with unique id, domainIdentifier for groupping up the the items
let item = CSSearchableItem(uniqueIdentifier: "1", domainIdentifier : "album-1", attributeSet: attributeSet)
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([Item]) { error in
if error != nil {
//handle error
} else {
//index success
}
}
Same API as hand off but the type checked against is CSSearchableItemActionType
func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool {
//handle the search result
if userActivity.activityType == CSSearchableItemActionType {
let uniqueIdentifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String
}
return true
}
same method as adding item to index
func indexSearchableItems(items: [CSSearchableItem], completionHandler:
((NSError?) -> Void)?)
delete items by identifiers
func deleteSearchableItemsWithIdentifiers(identifiers: [String],
completionHandler: ((NSError?) -> Void)?)
by domain identifiers
func deleteSearchableItemsWithDomainIdentifiers(domainIdentifiers: [String],
completionHandler: ((NSError?) -> Void)?)
or all
func deleteAllSearchableItemsWithCompletionHandler(completionHandler: ((NSError?) -> Void)?)
CSSearchableIndexDelegate
for observe any indexing changesAs some of the website mirrors the conten of the app. Search in iOS 9 can also shows the results from those websites.
Enable app search
Showing the app banner promotion on the top of the website
Related session: seamless linking to your app
Added twitter cards and Facebook App links as well
Besides showing title and description, images or other media can also used for search results.
Rating, offer, price ranges, interaction counts, organization and recipe
Phone number, directions or playing audio or video are actionable for iOS search results.
check below for more info
Resources | Link |
---|---|
App Search Developer Site | http://developer.apple.com/ios/search/ |
Twitter’s Cards Protocol | http://dev.twitter.com/cards/mobile |
Facebook’s App Links | http://applinks.org |
schema.org | http://schema.org |
Open Graph | http://ogp.me |
NSUserActivity.relatedUniqueIndentifer
should same as CSSearchableItem.uniqueIdentifier