简体   繁体   中英

Getting url tag value from Bluemix push notification

I need to pass the url along with the notification message using Bluemix Rest API. According to the docs

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

The above rest call should send the message and the url. But when i tried to parse the Json object from the notification there is no tag that sends the url.

在此处输入图片说明

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

 };
 MFPPush.registerNotificationsCallback(notification);
    }}

The above is the code that I am registering the notification from javascript using Cordova app.

The code below shows the AppDelegate code on iOS:

-(void)application:(UIApplication *)application

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

[[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo];

}

When i have put a log statement for userInfo in AppDelegate, the following log is displayed:

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

Its getting displayed in the dictionary. But how to get the url value from it?

@Rahul,您必须在func didReceiveRemoteNotification(notification: NSDictionary?) {}方法内添加notif["url"] = notification?.valueForKey("url") func didReceiveRemoteNotification(notification: NSDictionary?) {}方法以显示在通知弹出窗口中。

Open the app in Xcode and go to CDVMFPPush.swift file and locate the func didReceiveRemoteNotification(notification: NSDictionary?)

Add the following line inside the above function

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

Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM