gpt4 book ai didi

ios - 无法恢复 NSUserActivity 的 userInfo

转载 作者:搜寻专家 更新时间:2023-10-30 20:15:13 26 4
gpt4 key购买 nike

我有一个应用程序,您可以在其中找到我们大学的员工,并通过电子邮件与他们联系。当你找到某人并查看详细信息时,将创建一个 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 包含正确的标题和类型。但是 userInforequiredUserInfoKeys 都是空的。

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

NSLog(@"Activity: %@\nInfo: %@", userActivity.activityType, userActivity.requiredUserInfoKeys);

return YES;
}

我不明白,我在哪里犯了错误。我已经读过 this , 但它没有帮助。

PS:_displayedPerson.personID 是一个 NSNumber 并且 [_displayedPerson completeName] 返回一个 NSString

最佳答案

我在 Apple 开发者论坛中找到了答案。 updateUserActivityState: 需要被覆盖。

- (void)updateUserActivityState:(NSUserActivity *)userActivity {
[userActivity addUserInfoEntriesFromDictionary:@{@"id" : _displayedPerson.personID, @"fullName" : [_displayedPerson completeName]}];
}

我不知道为什么我必须这样做,但它有效。希望这也能帮助其他人。

关于ios - 无法恢复 NSUserActivity 的 userInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34473480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com