cordovaibm-cloudcordova-pluginsibm-mobile-servicesibm-cloud-plugin

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.

enter image description here

 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?


Solution

  • 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.