1

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?

Rahul Kalidindi
  • 4,666
  • 14
  • 56
  • 92

2 Answers2

1

@Rahul you have to add notif["url"] = notification?.valueForKey("url") inside the func didReceiveRemoteNotification(notification: NSDictionary?) {} method to display in the notification popup.

pradeep sg
  • 193
  • 1
  • 6
  • I think u mistook that I am not able to get the info from the dictionary. But the issue here is that I am not able to get the key value pair of url from notification itself. – Rahul Kalidindi Sep 08 '16 at 13:34
1

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.

Ananth
  • 205
  • 3
  • 13