NSMutableArray *searchableItems = [NSMutableArray array];

for (int i = 1; i < 100; i++) {

    CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:@"vvv"];

    attributeSet.title = [NSString stringWithFormat:@"warwick%d",i];
    attributeSet.contentDescription = @"warwickDescriotion";
    UIImage *image = [UIImage imageNamed:@"1"];
    attributeSet.thumbnailData = UIImagePNGRepresentation(image);

    CSCustomAttributeKey *lat = [[CSCustomAttributeKey alloc]initWithKeyName:@"lat"];
    [attributeSet setValue:@"123456789" forCustomKey:lat];

    CSSearchableItem *item = [[CSSearchableItem alloc]initWithUniqueIdentifier:[NSString stringWithFormat:@"warwick%d",i] domainIdentifier:nil attributeSet:attributeSet];

    [searchableItems addObject:item];
}

[[CSSearchableIndex defaultSearchableIndex]indexSearchableItems:searchableItems completionHandler:nil];

我已经用searchableItems设置了一些customKey,如何在AppDelegate中获得customKeyValue
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler

最佳答案

AppDelegate continueUserActivity方法唯一获得的是CSSearchableItemuserInfo词典中userActivity的唯一标识符,仅此而已。

09-18 05:49