Skip to content

Spotlight search and deeplinking (iOS)

Since iOS 9 Apple released a great feature to explore content inside Apps, that is spotlight. It can index searchable content and keywords into iOS system, and when customer type the content in spotlight, corresponding Apps will disappear.

StreetHawk provides easy to use APIs for supporting spotlight. There are two steps:

1. Index the content and keyword

StreetHawk provides an API to index the content to system.

[StreetHawk indexSpotlightSearchForIdentifier:@"1" forDeeplinking:@"hawk://testsearch?id=12" withSearchTitle:@"An interesting restaurant for kids." withSearchDescription:@"It has many toys for kids, \nand the table is colorful." withThumbnail:[UIImage imageNamed:@"icon.png"] withKeywords:@[@"child", @"play"]];

The parameters are listed below:

Parameter name Type Comment
identifier NSString Mandatory, the identifier of this spotlight item. It's unique for each item, if use same identifier it means update to existing item.
deeplinking NSString Optional, the deeplinking url of this item.

It will be used in `StreetHawk.openUrlHandler = ^(NSURL *openUrl) {}` when customer clicks the search result.

If `deeplinking` is empty, `StreetHawk.openUrlHandler = ^(NSURL *openUrl) {}` will get `identifier` as `openUrl`.
searchTitle NSString Optional, the title displaying in search result as title.
searchDescription NSString Optional, the description displaying in search result as description.
thumbnail UIImage Optional, the thumbnail displaying in search result in left.
keywords NSArray Optional, the keywords used for search, and it doesn't display in search result.

There are also APIs for deleting the spotlight items.

When search in spotlight by typing any words inside title or description or keyword, the App will be listed.

2. Handle deeplinking when click search result

When customer clicks search result, openUrlHandler is called with deeplinking url returns.

StreetHawk.openUrlHandler = ^(NSURL *openUrl)
{
}