Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在推送通知中显示消息正文_Ios_Swift_Push Notification - Fatal编程技术网

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

Ios 在推送通知中显示消息正文,ios,swift,push-notification,Ios,Swift,Push Notification,当我收到推送通知时,我会收到follow消息,并且同样的JSON也会显示给用户。当用户收到推送通知时,我只想在正文中显示数据,而不是显示整个JSON 在aps下我得到了这个 { \"Type\":\"TestType\", \"NotificationId\":\"40\", \"ImageUrl\":\"\", \"UserId\":1, \"Data\":\"Testing Push Notification\" } 如何在推送通知的消息体中显示数据 func

当我收到推送通知时,我会收到follow消息,并且同样的
JSON
也会显示给用户。当用户收到推送通知时,我只想在正文中显示
数据,而不是显示整个
JSON

在aps下我得到了这个

{
   \"Type\":\"TestType\",
   \"NotificationId\":\"40\",
   \"ImageUrl\":\"\",
   \"UserId\":1,
   \"Data\":\"Testing 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"]{

            }
        }
    }
}
例如,更新正确的格式

{
    "aps": {
        "alert": "Hello World",
        "sound": "default"
    },
    "Person": {
        "Address": "this is a test address",
        "Name": "First Name",
        "Number": "023232323233"
    }
}

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

{
“aps”:{
“警报”:{

“title”:“嘿!但是如何设置标题?我可以获取警报[“数据”],因为我已经将其转换为SwiftyJSON。但是如何在消息上显示它?”如何在消息上显示它“。你想在哪里显示?当应用程序未激活时,在手机上显示。当我们收到推送屏幕时,它应该显示该主体,而不是它当前正在执行的整个json对象。@带“内容可用”的Nitesh”:1当应用程序位于后台时,块会自动显示。我是指消息,当您看到应用程序图标、正文、消息时。就像WhatsApp或Facebook通知一样。这就是您想要的?
{
    "aps": {
        "alert": "Hello World",
        "sound": "default"
    },
    "Person": {
        "Address": "this is a test address",
        "Name": "First Name",
        "Number": "023232323233"
    }
}