2 Replies
      Latest reply on Dec 18, 2019 6:38 AM by edorphy
      Thomas E. Level 1 Level 1 (0 points)

        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?