WatchKit handleActionWithIdentifier: forRemoteNotification not called

I have a simple static interface for notifying Apple watches: enter image description here

and in PushNotificationPayload:

{
    "aps": {
        "alert": {
            "body": "123You have a new message",
            "title": "myApp"
        },
        "category": "respond"
    },

    "WatchKit Simulator Actions": [
        {
            "title": "View Message",
            "identifier": "viewMsgBtn"
        }
    ],

    "customKey": "customKey"
}

and implement the method in InterfaceController

- (void)handleActionWithIdentifier:(NSString *)identifier
             forRemoteNotification:(NSDictionary *)remoteNotification
{
    NSLog(@"Handling remote notification: %@ with identifier: %@", remoteNotification, identifier);
//    [self.lbTest setText:[NSString stringWithFormat:@"Notification: %@",remoteNotification.description]];
}

and I run the simulator with a notification:

enter image description here

The awakeWithContext method is called in the InterfaceController and after clicking the "View message" button, and it is loaded into the apple watch application interface.

the willActivate method in the InterfaceController is called. but handleActionWithIdentifier forRemoteNotification is not called ... any idea?

+4
source share
2 answers

I experienced something similar (in Swift), but then I realized that I implemented

handleActionWithIdentifier(identifier: String?, forRemoteNotification remoteNotification: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject])

instead

handleActionWithIdentifier(identifier: String?, forRemoteNotification remoteNotification: [NSObject : AnyObject])

, , .

+1

( ), Long-Look ( ). : https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/BasicSupport.html#//apple_ref/doc/uid/TP40014969-CH18-SW1

NotificationController.m :

- (void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
    // This method is called when a remote notification needs to be presented.
    // Implement it if you use a dynamic notification interface.
    // Populate your dynamic notification interface as quickly as possible.
    //
    // After populating your dynamic notification interface call the completion block.

    completionHandler(WKUserNotificationInterfaceTypeCustom);
}

WKUserNotificationInterfaceTypeCustom. (< 10 ), ( ), . ( ).

.

0

All Articles