本文介绍了WatchKit handleActionWithIdentifier : forRemoteNotification 未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Apple Watch 通知的简单静态接口,如下所示:

I have a Simple Static Interface for the apple watch notification as follow:

并在PushNotificationPayload中如下:

and in the PushNotificationPayload are as follow:

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

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

    "customKey": "customKey"
}

并在InterfaceController中实现方法

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]];
}

我用通知运行模拟器:

InterfaceController 中的awakeWithContext 方法被调用,点击View Message 按钮后,它会加载到我的Apple Watch 应用界面.

the awakeWithContext method in InterfaceController is called, and after clicking the View Message button and it loads to my apple watch app interface.

InterfaceController 中的 willActivate 方法被调用.但是没有调用用于远程通知的 handleActionWithIdentifier ......有什么想法吗?

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

推荐答案

我遇到了类似的事情(在 Swift 中),但后来意识到我已经实现了

I was experiencing something similar (in Swift) but then realized I had implemented

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

代替

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

前者适用于用户提供文本响应的情况,此处不适用.

The former is for cases where the user provides a text response, which is not applicable here.

这篇关于WatchKit handleActionWithIdentifier : forRemoteNotification 未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:21