【问题标题】:WatchKit handleActionWithIdentifier : forRemoteNotification is not calledWatchKit handleActionWithIdentifier:不调用 forRemoteNotification
【发布时间】:2015-06-15 08:11:25
【问题描述】:

我有一个用于 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 应用界面。

InterfaceController 中的 willActivate 方法被调用。 但是没有调用用于RemoteNotification 的handleActionWithIdentifier ... 有什么想法吗?

【问题讨论】:

  • 遇到了类似的问题,请问您解决这个问题了吗?
  • 不...还是不知道...
  • 你有没有弄清楚问题是什么?

标签: push-notification apple-watch


【解决方案1】:

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

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

而不是

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

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

【讨论】:

    【解决方案2】:

    您不仅需要实现短外观接口(静态接口),还需要实现长外观接口(动态接口)。本指南非常完美: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。如果你这样做快速填充(

    问候。

    【讨论】:

    • 我确实在 NotificationController 中实现了这个方法。并且还在NotificationController和InterfaceController中实现了handleActionWithIdentifier forRemoteNotification,但是它们都没有被调用。
    猜你喜欢
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多