IMPLEMENTING SPOTLIGHT IN YOUR APP

IMPLEMENTING SPOTLIGHT IN YOUR APP

Hey Readers, hope you have a great time reading the posts, today we will have a quick look at Spotlight search feature of iOS 9. Spotlight Search is new feature of iOS9 which enables us to provide content search of our Application to the Spotlight API.

By implementing spotlight user can search content in our without even opening our app. So are you ready for the Spotlight search drive ? Lets begin.

Step 1 :
Add following frameworks to

  • CoreSpotlight Framework
  • Mobile Core Service Framework
  • Step 2 :

    Add following code to your view file.

    1. CSSearchableItemAttributeSet *attributeSet;
    2. attributeSet = [[CSSearchableItemAttributeSet alloc]
    3. initWithItemContentType:(NSString *)kUTTypeImage];
    4. attributeSet.title = @"Bhumesh";
    5. attributeSet.contentDescription = @"Super Spidy";
    6. attributeSet.keywords = @[@"bhumesh", @"spiderman",@"spidy"];
    7. UIImage *image = [UIImage imageNamed:@"spidy"];
    8. NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
    9. attributeSet.thumbnailData = imageData;
    10. CSSearchableItem *item = [[CSSearchableItem alloc]
    11. initWithUniqueIdentifier:@"com.aadil.SpotliteSearch"
    12. domainIdentifier:@"com.aadil.SpotliteSearch"
    13. attributeSet:attributeSet];
    14. [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item]
    15. completionHandler: ^(NSError * __nullable error) {
    16. if (!error)
    17. NSLog(@"Search item indexed");
    18. }];
    1. CSSearchableItemAttributeSet *attributeSet;
    2. attributeSet = [[CSSearchableItemAttributeSet alloc]
    3. initWithItemContentType:(NSString *)kUTTypeImage];
    4. attributeSet.title = @"Bhumesh";
    5. attributeSet.contentDescription = @"Super Spidy";
    6. attributeSet.keywords = @[@"bhumesh", @"spiderman",@"spidy"];
    7. UIImage *image = [UIImage imageNamed:@"spidy"];
    8. NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
    9. attributeSet.thumbnailData = imageData;
    10. CSSearchableItem *item = [[CSSearchableItem alloc]
    11. initWithUniqueIdentifier:@"com.aadil.SpotliteSearch"
    12. domainIdentifier:@"com.aadil.SpotliteSearch"
    13. attributeSet:attributeSet];
    14. [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item]
    15. completionHandler: ^(NSError * __nullable error) {
    16. if (!error)
    17. NSLog(@"Search item indexed");       

      Here make sure you supply your app bundle name “com.mybundle.SpotliteSearch” and proper keywords and you are good to go.

      Run your project press control + shift + h and search you will see following search results except image as you need to add image to your results too.  

要查看或添加评论,请登录

BhuShan PaWaR的更多文章

  • iOS 11?—?Core ML

    iOS 11?—?Core ML

    I introduced Core ML which is a general machine learning framework. Apple also provide frameworks for specific areas.

  • Protocol-oriented Programming in Swift

    Protocol-oriented Programming in Swift

    Protocols are used to define a “blueprint of methods, properties, and other requirements that suit a particular task or…

    1 条评论
  • iOS 10 Push Notifications

    iOS 10 Push Notifications

    Images, GIFs, Audio and Video You can now send rich media in a push notification, including images, GIFs, audio, and…

    3 条评论
  • Apple Keynote Event (September 7, 2016)

    Apple Keynote Event (September 7, 2016)

    Apple has launched the two new members of IPhone Family. iPhone 7 and iPhone 7 Plus.

  • NSURLConnection to NSURLSession

    NSURLConnection to NSURLSession

    got its start a decade ago, with the original release of Safari in 2003, as an abstraction on top of the Core…

    3 条评论
  • Apple Pay

    Apple Pay

    Mobile payments are the hot phrase of the season. Since Apple Pay’s announcement in 2014 and now Samsung and…

  • WHATS NEW IN IOS 9

    WHATS NEW IN IOS 9

    Multitasking Enhancements for iPAD For Multitasking on iPAD, iOS 9 has introduced bunch of new views which are : Slide…

    1 条评论
  • IOS9

    IOS9

    Apple has been always improvising the iOS & developer tools this time keeping in mind the smaller size devices like 8…

  • DEEP LINKING

    DEEP LINKING

    Deep Linking at first seems to be very heavy & new concept but its actually very useful. But lets first understand what…

  • ASPECT RATIOS & AUTOLAYOUT

    ASPECT RATIOS & AUTOLAYOUT

    Auto Layout at first seems to be very boring and unresponsive, did you felt the same ? The first time I started with I…

    1 条评论

社区洞察

其他会员也浏览了