Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我们返回应用程序时,如何获取我们在spotlight search中编写的搜索文本值_Ios_Iphone_Ipad_Xcode7_Corespotlight - Fatal编程技术网

Ios 当我们返回应用程序时,如何获取我们在spotlight search中编写的搜索文本值

Ios 当我们返回应用程序时,如何获取我们在spotlight search中编写的搜索文本值,ios,iphone,ipad,xcode7,corespotlight,Ios,Iphone,Ipad,Xcode7,Corespotlight,大家好,我目前正在使用新的iOS 9功能spotlight feature。我无法获取我在spotlight search中编写的文本,当我们从spotlight search返回到我的应用程序时,我正在使用CoreSpootlight框架 - (void)setUpCoreSpotLightSearch { self.userActivity = [[NSUserActivity alloc] initWithActivityType

大家好,我目前正在使用新的iOS 9功能spotlight feature。我无法获取我在spotlight search中编写的文本,当我们从spotlight search返回到我的应用程序时,我正在使用CoreSpootlight框架

- (void)setUpCoreSpotLightSearch {

    self.userActivity = [[NSUserActivity alloc]
                         initWithActivityType:@"com.pulpstrategy.spotlight"];
    self.userActivity.title = @"Test";

    self.userActivity.userInfo = @{@"subjectid" : @"5" , @"subjecttype" : @"type"};
    NSLog(@"userInfo %@", self.userActivity.userInfo);

    self.userActivity.eligibleForSearch = YES;
    self.userActivity.eligibleForPublicIndexing = YES;
    self.userActivity.webpageURL = [NSURL URLWithString:@"http://www.google.com"];

    CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:(NSString *)kUTTypeImage];
    attributeSet.title = @"My";
    attributeSet.contentDescription = @"";
    attributeSet.keywords = [NSArray arrayWithObjects:@"Hello",@"Welcome",@"Utkarsh", nil];
    UIImage *img = [UIImage imageNamed:@"A.jpeg"];
    NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(img)];
    attributeSet.thumbnailData = imgData;

    CSSearchableItem *item = [[CSSearchableItem alloc]initWithUniqueIdentifier:@"com.pulpstrategy.spotlight" domainIdentifier:@"spotlight.CoreSpotLight" attributeSet:attributeSet];

    [[CSSearchableIndex defaultSearchableIndex]indexSearchableItems:[NSArray arrayWithObject:item] completionHandler:^(NSError * _Nullable error) {
        if (!error) {
            NSLog(@"Item = %@",error.localizedDescription);
        }
    }];

}
在我使用的搜索之后:

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

    userActivity.eligibleForSearch = YES;

    NSLog(@"Handler = %@",restorationHandler);

    if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) {
        // This activity represents an item indexed using Core Spotlight, so restore the context related to the unique identifier.
        // The unique identifier of the Core Spotlight item is set in the activity’s userInfo for the key CSSearchableItemActivityIdentifier.

        NSString *uniqueIdentifier = [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
        NSString *valueForUID = [self.userActivity valueForKey:uniqueIdentifier];// The app is crashed that line piece of code.

        ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

       NSLog(@"value for UID = %@",valueForUID);

        [navController pushViewController:viewController animated:YES];

    }
    return YES;
}