1

Bluemix Rest API を使用して、通知メッセージとともに URL を渡す必要があります。ドキュメントによると

{"message": {
"alert": "Notification alert message","url":"test.test.com" }}

上記の残りの呼び出しは、メッセージと URL を送信する必要があります。しかし、通知から Json オブジェクトを解析しようとすると、URL を送信するタグがありません。

ここに画像の説明を入力

 MFPPush.registerDevice(settings, success, failure);
 var notification = function(notif){
     alert (JSON.stringify(notif));

 };
 MFPPush.registerNotificationsCallback(notification);
    }}

上記は、Cordova アプリを使用して JavaScript からの通知を登録しているコードです。

以下のコードは、iOS の AppDelegate コードを示しています。

-(void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

[[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo];

}

AppDelegate に userInfo のログ ステートメントを配置すると、次のログが表示されます。

{
    aps =     {
        alert =         {
            "action-loc-key" = "<null>";
            body = test;
        };
    };
    payload = "{\"nid\":\"5a379af\",\"tag\":\"Push.ALL\"}";
    url = URL;
}

辞書に表示されるようになりました。しかし、そこから url 値を取得する方法は?

4

2 に答える 2

1

Xcode でアプリを開き、CDVMFPPush.swiftファイルに移動して、func didReceiveRemoteNotification(notification: NSDictionary?)

上記の関数内に次の行を追加します

notif["url"] = notification?.valueForKey("url")

これがあなたを助けることを願っています。

于 2016-09-08T17:43:47.710 に答える