Watch -> iPhone handoff not working

Hi,


I'm trying to get Handoff from a WatchKit app to an iOS app to work (again). It probably worked in the past with the older notification APIs.


I validated Watch -> iPhone handoff works with some Apple supplied Apps.

However when I open in our app the notification on the watch, nothing is shown on the iPhone (app switch..) screen.


The Watchkit handoff code below is executed and no error is logged on the console


- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
    [super willActivate];
    [self startHandoff];
     // ...
}

- (void)startHandoff {
    NSString *documentURL = self.news.url;
    
    NSLog(@"updating user activity to %@", documentURL);
    
    if (@available(watchOS 5.0, *)) {
        NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:USER_ACTIVITY_TYPE];
           activity.userInfo = @{HAND_OFF_DOCUMENT_URL_KEY : documentURL};
        activity.title = self.news.headline;
        activity.eligibleForHandoff = YES;
        activity.needsSave = YES;
        // activity.targetContentIdentifier = documentURL;
        activity.requiredUserInfoKeys = [NSSet setWithObject:HAND_OFF_DOCUMENT_URL_KEY];
       
        [self updateUserActivity:activity];
        [activity becomeCurrent];
    } else {
        // Fallback on earlier versions
        
        [self updateUserActivity:USER_ACTIVITY_TYPE userInfo:@{HAND_OFF_DOCUMENT_URL_KEY : documentURL} webpageURL:nil];
    }

}

Originally the iOS App had the USER_ACTIVITY_TYPE just registered in the Info.plist under the NSUserActivityTypes key.

I also added for testing code when registering the (working) push notification handler:


- (void)registerForPushNotifications {
    
    UNNotificationCategory *newDocumentCategory = [UNNotificationCategory
                                                   categoryWithIdentifier:PUSH_NOTIFICATION_TYPE
                                                   actions:@[] // Default action is sufficient
                                                   intentIdentifiers:@[] // SiriKit only
                                                   options:UNNotificationCategoryOptionNone]; // UNNotificationCategoryOptionAllowAnnouncement
    
    UNNotificationCategory *handoverCategory = [UNNotificationCategory
                                                      categoryWithIdentifier:USER_ACTIVITY_TYPE
                                                      actions:@[] // Default action is sufficient
                                                      intentIdentifiers:@[] // SiriKit only

    UNUserNotificationCenter *nc = [UNUserNotificationCenter currentNotificationCenter];
    [nc setNotificationCategories:[NSSet setWithArray:@[newDocumentCategory, handoverCategory] ]];
    [nc requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert   completionHandler:^( BOOL granted, NSError *__nullable error ){
                                                     options:UNNotificationCategoryOptionNone];

Any hints how I can debug?

Replies

P.S.: The watch app <-> iPhone interaction works otherwise fine (syncing user defaults, sharing data in the session) but also in the Simulator handoff is simply not working

For discussion purposes, can you confirm if the syncing user defaults is working is happening from your iPhone to Watch P2P, or the watch is connected to infrastructure WiFi and circumventing the iPhone?

You mention testing in the Simulator, but doesn't Handoff require Bluetooth, which the Simulator does not support?