[英]Getting url tag value from Bluemix push notification
I need to pass the url along with the notification message using Bluemix Rest API. 我需要使用Bluemix Rest API将URL与通知消息一起传递。 According to the docs
根据文档
{"message": {
"alert": "Notification alert message","url":"test.test.com" }}
The above rest call should send the message and the url. 上面的rest调用应该发送消息和url。 But when i tried to parse the Json object from the notification there is no tag that sends the url.
但是,当我尝试从通知中解析Json对象时,没有发送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. 上面的代码是我使用Cordova应用程序从javascript注册通知的代码。
The code below shows the AppDelegate code on iOS: 以下代码显示了iOS上的AppDelegate代码:
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 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: 当我在AppDelegate中放置了userInfo的日志语句时,将显示以下日志:
{
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?
但是如何从中获取url值呢?
@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?)
在Xcode中打开应用程序,然后转到
CDVMFPPush.swift
文件,然后找到func didReceiveRemoteNotification(notification: NSDictionary?)
CDVMFPPush.swift
func didReceiveRemoteNotification(notification: NSDictionary?)
Add the following line inside the above function 在上面的函数中添加以下行
notif["url"] = notification?.valueForKey("url")
Hope this will help you. 希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.