I am implementing handoff from an apple watch app to the destination app on my iphone.
On one of the WatchKit Extension viewcontrollers i have the following code:
myActivity = [[NSUserActivity alloc]
initWithActivityType: @"com.newsApp.shownews"];
myActivity.userInfo = @{@"newsID":[self.newsID objectAtIndex:0]};
myActivity.title = @"shownews";
myActivity.delegate = self;
[myActivity becomeCurrent];
Then i add the following code in the continueUserActivity
inside the appDelegate of my destination iphone app:
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
{
if ([userActivity.activityType isEqual: @"com.newsApp.shownews"]) {
UIStoryboard *mainStoryboard = self.window.rootViewController.storyboard;
ShownewsViewController *detailViewController = (ShownewsViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"ShownewsViewController"];
detailViewController.post_ID = [userActivity.userInfo objectForKey:@"newsID"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
[self.window.rootViewController presentViewController:navigationController animated:YES completion:NULL];
}
return YES;
}
The problem is that userActivity.userInfo
is empty but the userActivity.activityType
is correctly set to com.newsApp.shownews
.
Try setting the requiredUserInfoKeys on your NSUserActivity object.