我有一个应用程序,您可以在其中找到我们大学的员工并通过电子邮件与他们联系。当你找到某人并查看详细信息时,NSUserActivity
会创建一个:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
//Create NSUserActivity for the person
NSUserActivity * activity = [[NSUserActivity alloc] initWithActivityType:CAUserActivityTypePerson];
activity.title = [_displayedPerson completeName];
activity.requiredUserInfoKeys = [NSSet setWithArray:@[@"id", @"fullName"]];
activity.userInfo = [NSDictionary dictionaryWithObjects:@[_displayedPerson.personID, [_displayedPerson completeName]] forKeys:@[@"id", @"fullName"]];
activity.keywords = [NSSet setWithObjects:[_displayedPerson completeName], [_displayedPerson institutionString], nil];
CSSearchableItemAttributeSet * contentAttributeSet = [[CSSearchableItemAttributeSet alloc] init];
contentAttributeSet.contentDescription = [_displayedPerson institutionString];
activity.contentAttributeSet = contentAttributeSet;
//make the activity active and searchable
self.userActivity = activity;
self.userActivity.eligibleForHandoff = NO;
self.userActivity.eligibleForSearch = YES;
self.userActivity.eligibleForPublicIndexing = NO;
self.userActivity.needsSave = YES;
[self.userActivity becomeCurrent];
NSLog(@"UserActivity created\nInfo: %@", self.userActivity.userInfo);
} else
NSLog(@"Did not create NSUserActivity! iOS 9 required!");
创建 UserActivity 时,NSLog(@"UserActivity created\nInfo: %@", self.userActivity.userInfo);
返回正确的userInfo
.
当我在聚光灯下找到条目(正确显示所有相关数据)并单击它时,该应用程序将被打开并被- (BOOL)application:continueUserActivity:restorationHandler:
调用并userActivity
包含正确的标题和类型。但是userInfo
和requiredUserInfoKeys
都是空的。
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
NSLog(@"Activity: %@\nInfo: %@", userActivity.activityType, userActivity.requiredUserInfoKeys);
return YES;
}
我不明白,我在哪里犯了错误。我已经读过这个,但它没有帮助。
PS:_displayedPerson.personID
是一个NSNumber
并[_displayedPerson completeName]
返回一个NSString