Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUserActivity handoff not working for custom data

I'm trying to test out the iOS 8.1 handoff feature with NSUserActivity between my iPhone and my iPad. For this, I tried both implementing my own solution, and to use Apple's PhotoHandoff project. However, it's not working.

If I provide a webpageURL, the handover works fine, but when I try to use userData or addUserInfoEntriesFromDictionary nothing works, and I can't for the life of me figure out what the catch is to make the data work.

Sample code:

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"com.company.MyTestApp.activity"];
activity.title = @"My Activity";
activity.userInfo = @ {};
//    activity.webpageURL = [NSURL URLWithString:@"http://google.com"];

self.userActivity = activity;

[self.userActivity becomeCurrent];
[self.userActivity addUserInfoEntriesFromDictionary:@ { @"nanananan": @[ @"totoro", @"monsters" ] }];

(I'm also unable to make it work with a Mac app with a corresponding activity type)

like image 936
Claus Jørgensen Avatar asked Nov 03 '14 13:11

Claus Jørgensen


1 Answers

I hope you found the solution already, but in case somebody stumbles upon this problem too, here is a solution. (Actually not very different from the previous answer)

Create user activity without userInfo, it will be ignored:

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"..."];
activity.title = @"Test activity";
activity.delegate = self;
activity.needsSave = YES;

self.userActivity = activity;
[self.userActivity becomeCurrent];

Implement the delegate to react to needSave events:

- (void)userActivityWillSave:(NSUserActivity *)userActivity {
    userActivity.userInfo = @{ @"KEY" : @"VALUE" };
}

When needsSave is set to YES this method will be called and userActivity will be updated.

Hope this helps.

like image 126
GregoryM Avatar answered Oct 15 '22 15:10

GregoryM