Developer/iOS

[iOS]iOS9 Sportlight 검색 추가하기

블로blow 2016. 1. 5. 16:23
728x90

1.Build Phases -> Link Binary With Libraries 에서

CoreSpotlight.framework 추가하기.


2. 설명이미지



3. 코드 작성

#import <CoreSpotlight/CoreSpotlight.h>

#import <MobileCoreServices/MobileCoreServices.h>


-(void)addSportlightSearchItem:(NSString*)title desc:(NSString*)desc keywords:(NSArray*)keywords isHaveImageData:(BOOL)imageDataAvailable imageData:(NSData*)imageData {

    CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString*)kUTTypeImage];

    attributeSet.title = title;

    attributeSet.contentDescription = desc;

    attributeSet.keywords = keywords;

    if(imageDataAvailable) {

        attributeSet.thumbnailData = imageData;

    }else {

        attributeSet.thumbnailData = NULL;

    }


    CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:desc domainIdentifier:desc attributeSet:attributeSet];

    [[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:@[item] completionHandler:^(NSError * __nullable error) {

        if(!error) {

            NSLog(@"등록완료");

        }

    }];

}



728x90