Since iOS9.0, apple has provided multiple ways for users to access information in apps, even if you don’t have an APP installed. Users can use Spotlight, HandOff, and more to get insight into your APP.

implementation

NSUserActivity

The NSUserActivity class provides methods that let you capture specific application states and navigation points that a user has previously visited, and then recover them using Handoff(learn more about enabling switching in your application). In iOS 8 and later apps, users want Handoff to help them start an activity on one device and continue it on another.

self.activity = [[NSUserActivity alloc] initWithActivityType:@"com.rw.activity"]; Self.activity. title = @" bhead "; self.activity.keywords=[NSSet setWithArray:@[@"tiger",@"horse"]]; self.activity.eligibleForSearch = YES; self.activity.eligibleForPublicIndexing = YES; [self.activity becomeCurrent]; ;Copy the code

Note: Implementation variables via NSUserActivity must be declared as global variables, otherwise they will be released with no effect

Core Spotlight framework

The Core Spotlight framework provides a way to index content in your application and manage private device indexes. Core Spotlight is best for indexing user-specific content, such as friends, items marked as favorites, items purchased, and so on. When you use the Core Spotlight API to make something searchable, you make it easy for users to find their content in Spotlight search results.

  • The text
    CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:@"my"]; attributeSet.title = @"first"; attributeSet.contentDescription = @"my app is running!" ; NSArray *secondArrayKey = [NSArray arrayWithObjects:@"second",@" test ",@"secondeVIew", nil]; attributeSet.contactKeywords = secondArrayKey; AttributeSet. Keywords = @[@" May 17 "]; attributeSet.addedDate = [NSDate date]; CSSearchableItem *searchItem = [[CSSearchableItem alloc] initWithUniqueIdentifier:@"cat" domainIdentifier:@"com.rw" attributeSet:attributeSet]; [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[searchItem] completionHandler:^(NSError * _Nullable error) { NSLog(@"%@",error.description); }];Copy the code

  • The phone
attributeSet.supportsPhoneCall = @(YES); attributeSet.phoneNumbers = @[@"15601856811"]; AttributeSet. AccountHandles = @ [@ "15601856811");

Note: The supportsPhoneCall and phoneNumbers properties will display a phone icon, but there is no response. Only when accountHandles is set, a call will be made after clicking

  • update

Update and increase is the same way, only the Item CSSearchableItemAttributeSet instance again

  • delete
  • DeleteAllSearchableItemsWithCompletionHandler: / / delete all
  • DeleteSearchableItemsWithDomainIdentifiers: completionHandler: / / according to delete Domain
  • DeleteSearchableItemsWithIdentifiers: completionHandler: / / according to delete Identifiers

Web Markup

If some or all of your application’s content is also available on your website, you can use Web tags to give users access to your content in search results. Using web tags allows Applebot Web crawler to index your content in Apple’s server-side index, making it available to all iOS users in Spotlight and Safari search results.

On your website, a Smart App clearly invites users who don’t install your App to download it from the App Store; it installs an easy way for users who do install your App to open a page inside it. The diagram below:

  • Support Universal Links

When you support universal links, iOS users can click a link to your website and seamlessly redirect to your installed app without going through Safari. If your app is not installed, click on a link to your website to open your website in Safari.

Refer to the article

App Search Programming Guide