在推送通知中显示消息正文

时间:2017-02-21 14:45:55

标签: ios swift push-notification

收到推送通知后,我收到了关注消息,同时向用户显示了JSON。我想只有当用户收到推送通知时才会在正文中显示Data,而不是显示整个JSON

在aps [“alert”]下我得到了这个

{
   \"Type\":\"TestType\",
   \"NotificationId\":\"40\",
   \"ImageUrl\":\"\",
   \"UserId\":1,
   \"Data\":\"Testing Push Notification\"
}

如何在推送通知的邮件正文中显示Data

2 个答案:

答案 0 :(得分:1)

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"]{

            }
        }
    }
}

请尝试发送推送通知流程格式,如果应用程序停留在后台,则自动显示正文消息:

[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"
    }
}

iOS Push Notification custom format

答案 1 :(得分:0)

  

aps 中的键由apple预先定义。但是您可以发送您的自定义   键 外部APS ,如下所示

> a:
... 3
3
  

Employee 是自定义键,您可以在其中设置自己的数据   根据要求