问题描述
我有一个用于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]];
}
然后我运行模拟器并发出通知:
and I run the simulator with notification:
InterfaceController中的awakeWithContext方法被调用,然后单击查看消息"按钮并将其加载到我的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 forRemoteNotification ...有什么主意吗?
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!