在推送通知中显示消息正文 [英] Displaying Message Body in Push Notification
本文介绍了在推送通知中显示消息正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我收到推送通知时收到关注消息,并且同样的 JSON
也显示给用户.当用户收到推送通知时,我只希望 Data
显示在正文中,而不是显示整个 JSON
.
I'm getting follow message when I receive Push Notification and the same JSON
is displayed to user too. I want only the Data
to be displayed in the body when user receives the push notification rather than displaying the whole JSON
.
在 aps["alert"] 下我明白了
under aps["alert"] I get this
{
\"Type\":\"TestType\",
\"NotificationId\":\"40\",
\"ImageUrl\":\"\",
\"UserId\":1,
\"Data\":\"Testing Push Notification\"
}
如何在推送通知的消息体中显示Data
How to display Data
in the message body of Push Notification.
推荐答案
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if(application.applicationState == UIApplicationState.Active) {
if let alertInfo = userInfo["aps"]?["alert"] as? Dictionary<String,String>{
if let title = alertInfo["Data"]{
}
}
}
}
请尝试发送推送通知流格式,如果应用程序停留在后台,则自动显示正文消息:
please try to send push notification flowing format and if application staying in background then automatic showing body message :
[aps: {
alert = {
body = "Testing Push Notification";
title = "New Message";
NotificationId= "536"
};
sound = default;
}]
更新正确的格式例如
{
"aps": {
"alert": "Hello World",
"sound": "default"
},
"Person": {
"Address": "this is a test address",
"Name": "First Name",
"Number": "023232323233"
}
}
这篇关于在推送通知中显示消息正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文