12 Replies
      Latest reply on Aug 30, 2015 12:32 PM by rwforsythe
      smufu Level 1 Level 1 (0 points)

        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]
            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.



        • Re: NSUserActivity missing userInfo on continueUserActivity
          joeltuni Level 1 Level 1 (0 points)

          Having the same issue, indexing and activityType are working fine but userinfo has 0 items on application continueUserActivity

          Edit: The problem is that userActivity gets deallocated after the method you called it in, you need to create a strong referenced property so that its retained.

            • Re: NSUserActivity missing userInfo on continueUserActivity
              Level 1 Level 1 (0 points)

              Did this really fix your problem? Because my userActivity has a strong referenece (otherwise the results don't even appear on the spotlight search). The problem comes later, when I click on the spotlight result and continueUserActivity is called, where (in my understanding) the object is a complete new one with an empty UserInfo, all other information, litke the title, is there.

                • Re: NSUserActivity missing userInfo on continueUserActivity
                  shortstuffsushi Level 1 Level 1 (0 points)

                  Hey guys, I'm seeing the same issues described here:


                  1. You must keep a strong reference to the Activity you create, or it will not be indexed (even if you call becomeCurrent before the end of the method).

                  2. UserInfo is not coming through, regardless.


                  These both seem like bug behaviors, and if you haven't already, I encourage you to log them on bugreport.apple.com, so the engineers are made aware as well (I'm guessing they don't actively monitor all the posts here).

              • Re: NSUserActivity missing userInfo on continueUserActivity
                John S Level 1 Level 1 (10 points)

                I was able to get mine working by filling in the requiredUserInfoKeys property, like this


                self.userActivity.requiredUserInfoKeys = [NSSet setWithArray:self.userActivity.userInfo.allKeys];
                  • Re: NSUserActivity missing userInfo on continueUserActivity
                    cwagdev Level 1 Level 1 (20 points)

                    That didn't do it for me, I had to implement the following.


                      override func updateUserActivityState(activity: NSUserActivity) {
                        activity.addUserInfoEntriesFromDictionary(["id": employee.objectId])


                    For whatever reason when you tie your NSUserActivity instance to UIResponder.userActivity it likes to wipe out your userInfo dictionary. So I found that I either had to override this method and set the userInfo keys I am interested in each time, or don't use UIResponder's property at all and have your own strong reference, but you will need to make it current and resign current at the appropriate times (viewDidAppear/Disappear) worked for me. But I find the above approach cleaner and it doesn't feel like it's working against the system.


                    Hope this helps someone else...

                  • Re: NSUserActivity missing userInfo on continueUserActivity
                    rwforsythe Level 1 Level 1 (0 points)

                    UPDATE: Behavior here is different on iOS 8 and iOS 9. The only reliable way to get this working is to use the userActivityWillSave: callback to set userInfo. It's listed here as a best practice, but it seems to be the only reliable implementation approach.




                    FWIW, I was having this issue. I was lucky that one of my Activity types worked and the other didn't:


                    Activity: Walking

                    (UserInfo x1,y1)

                    (UserInfo x2,y2)

                    (UserInfo x3,y3)

                    Activity: Standing

                    (UserInfo x4,y4)

                    Activity: Walking



                    I got userInfo if the handoff occured when standing but not walking. I got other properties such as webpageURL in all cases; just userInfo came through null.


                    The fix for me was to invalidate & recreate the NSUserActivity object every time (e.g. when Walking to x2/y2 from x1/y1), instead of only when Activity type changed (e.g. from walking to standing). This is very much not the way the doc is written, but fixed the issue.


                    Although I should be doing as recommended by Apple:

                    To update the activity object’s userInfo dictionary efficiently, configure its delegate and set its needsSave property to YES whenever the userInfo needs updating. At appropriate times, Handoff invokes the delegate’s userActivityWillSave: callback, and the delegate can update the activity state.


                    [Note: issue occurred on iOS 9 devices running code built on Xcode 6.x. Haven't tested Xcode 7 yet, and issue may not occur on iOS 8.]