I am adding 2 crucial information NSUserActivity userInfo. But when I try to get those information on continueUserActivity, the userInfo is empty.
Here is how I am adding the info to NSUserActivity:
self.userActivity = [[NSUserActivity alloc] initWithActivityType:@"com.mysite.example"]; self.userActivity.title = rettt; self.userActivity.userInfo = @{@"subjectid" : subject.subjectId , @"subjecttype" : @"type"}; NSLog(@"userInfo %@", self.recipeUserActivity.userInfo); self.userActivity.eligibleForSearch = YES; self.userActivity.eligibleForPublicIndexing = YES; self.userActivity.webpageURL = [NSURL URLWithString:[APIHelper websiteURL:previewUrl]]; CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage]; attributeSet.title = rettt; attributeSet.contentDescription = @"Description"; attributeSet.thumbnailData = image; attributeSet.thumbnailURL = [NSURL URLWithString:snapshotUrl]; self.userActivity.contentAttributeSet = attributeSet; [self.userActivity becomeCurrent];
Here is how I am trying to recover the information:
if ([userActivity.activityType isEqualToString:@"com.mysite.example"]){ if ([userActivity.userInfo objectForKey:@"subjecttype"] && [userActivity.userInfo objectForKey:@"subjectid"]) { //Open app page }else { return false; } }else if ([[userActivity activityType] isEqualToString:CSSearchableItemActionType]) { if ([userActivity.userInfo objectForKey:@"kCSSearchableItemActivityIdentifier"]) { //open app page } }
Do you see anything wrong with this code?
Activity type of CSSearchableItemActionType works better, since I do have at least the kCSSearchableItemActivityIdentifier, but userInfo is empty regardless.
Thanks!
Thanks! What worked for me was a combination of cwagdev and John S answers. I had to add both:
When creating my NSUserActivity I had to add:
self.userActivity.userInfo = @{@"subjectId" : self.subjectId}; self.userActivity.requiredUserInfoKeys = [NSSet setWithArray:self.recipeUserActivity.userInfo.allKeys];
And I also had to overwrite updateUserActivityState on my view controller:
-(void)updateUserActivityState:(NSUserActivity *)userActivity { [userActivity addUserInfoEntriesFromDictionary:@{@"subjectId" : self.subjectId}]; }
Now I have all the info I need when continueUserActivity gets called.
Thanks!