我有一个用于Apple Watch通知的简单静态界面,如下所示:
并在PushNotificationPayload中如下:
{
"aps": {
"alert": {
"body": "123You have a new message",
"title": "myApp"
},
"category": "respond"
},
"WatchKit Simulator Actions": [
{
"title": "View Message",
"identifier": "viewMsgBtn"
}
],
"customKey": "customKey"
}
并在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 app界面。
调用InterfaceController中的willActivate方法。 但是没有调用handleActionWithIdentifier forRemoteNotification ... 任何想法?
答案 0 :(得分:1)
我遇到了类似的东西(在Swift中)但后来意识到我已经实现了
handleActionWithIdentifier(identifier: String?, forRemoteNotification remoteNotification: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject])
而不是
handleActionWithIdentifier(identifier: String?, forRemoteNotification remoteNotification: [NSObject : AnyObject])
前者适用于用户提供文本响应的情况,此处不适用。
答案 1 :(得分:0)
您不仅需要实现短视图接口(静态接口),还需要实现长视图接口(动态接口)。本指南非常完美: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秒)apple watch show Long-Look Interface(动态界面),允许执行操作。否则短视(静态界面)。
问候。