如何在聚光灯搜索中输入文字?

时间:2017-08-03 06:42:17

标签: ios objective-c corespotlight

我在我的应用中实施了聚光灯搜索。它与静态文本一起工作正常。我想获取在聚光灯搜索栏中输入的文本,以便我可以根据它显示文本。

-(void)setUpCoreSpotlight
{

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

attributeSet.displayName = [NSString stringWithFormat:@"%@ - Currently playing with student %@",kApplicationName,[[ModelDataManager sharedModelManager] objSelectedStudent].StudentName];
attributeSet.title = kApplicationName;
attributeSet.contentDescription = [NSString stringWithFormat:@"Curriculums assigned to %@ : %@",[[ModelDataManager sharedModelManager] objSelectedStudent].StudentName, [[ModelDataManager sharedModelManager] objSelectedStudent].CurriculumName];

NSMutableArray *arrStudents = [[[ModelDataManager sharedModelManager]arrStudents] valueForKey:@"StudentName"];
NSMutableArray *arrKeywords = [[NSMutableArray alloc]initWithObjects:@"student",@"colorskit",@"play",@"prrogram", nil];
[arrKeywords addObjectsFromArray:arrStudents];

attributeSet.keywords = arrKeywords;
UIImage *image = [UIImage imageNamed:@"CC-Cover"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;


CSSearchableItem *item1 = [[CSSearchableItem alloc]
                           initWithUniqueIdentifier:@"program"
                           domainIdentifier:@"http://www.colorsacademy.com/in/"
                           attributeSet:attributeSet];

attributeSet = [[CSSearchableItemAttributeSet alloc]
                initWithItemContentType:(NSString *)kUTTypeItem];    
attributeSet.displayName = kApplicationName;
attributeSet.title = kApplicationName;
attributeSet.contentDescription = @"You can teach this program ";
attributeSet.keywords = keywords;
image = [UIImage imageNamed:@"enzymes-cover"];
imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
attributeSet.thumbnailData = imageData;
...
...
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)activity restorationHandler:(void (^)(NSArray *))restorationHandler
{

NSString * valueCSSearchableItemActionType;
BOOL wasHandled = NO;

if ([CSSearchableItemAttributeSet class]) //iOS 9
{

    valueCSSearchableItemActionType = CSSearchableItemActionType;

} else { // iOS 8 or earlier

    valueCSSearchableItemActionType = @"not supported";
}

if ([activity.activityType isEqual: valueCSSearchableItemActionType])
    //Clicked on spotlight search, item was created via CoreSpotlight API
{

    //…handle the click here, we can assume iOS 9 from now on…
    NSString * activityIdentifier = [activity.userInfo valueForKey:CSSearchableItemActivityIdentifier];
    wasHandled = YES;
    NSLog(@"Continuing user activity %@", activityIdentifier);

} else {

    //the app was launched via Handoff protocol
    //or with a Universal Link
}

return wasHandled;
}

我无法获取已输入的文字。甚至"应用程序continueUserActivity"方法也没有被调用。如果有人有任何想法,请帮忙。

0 个答案:

没有答案
相关问题