GCM推送通知时,iOS应用程序是在后台 [英] GCM push notification when iOS app is in the background
问题描述
我试图发送推送通知到我的iOS应用程序与GCM。该应用程序不会得到通知时,它的背景,但是当它在前台它。我是用PHP脚本还直接将消息发送到APNS测试推送通知和它的工作背景。
发送到GCM的JSON(我是从一个REST客户端测试其发送)
{
要:令牌......
通知:{
头衔:GCM TITLE
身:从GCM
徽章:1
声音:默认
}
}
不工作:
从GCM收到didReceiveRemoteNotification的用户信息:
收到通知:[APS:{
警报= {
身体=从GCM
标题=GCM TILE
};
徽章= 1;
听起来=默认值;
},gcm.message_id:123 ...]
工作:
该用户信息收到PHP脚本时发送(我还添加了与Message_ID到JSON,看是否这就是问题所在)
收到通知:[APS:{
警报= {
身体=从PHP;
标题=PHP TITLE
};
徽章= 2;
听起来=默认值;
},gcm.message_id:123 ...]
我尝试添加content_available的JSON用不同的组合,但没有帮忙,Content-Type和授权请求报头也被设置:
内容类型:应用程序/ JSON
授权:关键= ...
在情况下,如果有人有相同的问题,解决的办法是我的优先级补充说:高到JSON。这样,我得到通知的背景。
{
要:令牌......
优先级:高,
通知:{
头衔:GCM TITLE
身:从GCM
徽章:1
声音:默认
}
}
I'm trying to send push notifications to my iOS app with GCM. The app doesn't get the notification when it's in the background but it does when it's in the foreground. I was testing the push notifications with a PHP script also which sends the message directly to the APNS and it's working in the background.
The JSON sent to GCM: (I'm sending it from a rest client for testing)
{
"to" : "token...",
"notification" : {
"title": "GCM TITLE",
"body" : "FROM GCM",
"badge": "1",
"sound": "default"
}
}
Not working: The userInfo received from GCM in didReceiveRemoteNotification:
Notification received: [aps: {
alert = {
body = "FROM GCM";
title = "GCM TILE";
};
badge = 1;
sound = default;
}, gcm.message_id: 123...]
Working: The userInfo received when sent from the PHP script (I also added the message_id to the JSON to see if that's the problem)
Notification received: [aps: {
alert = {
body = "FROM PHP";
title = "PHP TITLE";
};
badge = 2;
sound = default;
}, gcm.message_id: 123...]
I tried adding content_available to the JSON with different combinations but didn't help, the Content-Type and Authorization request headers are also set:
Content-Type:application/json
Authorization:key=...
In case if someone has the same problem, the solution was for me to add the "priority": "high" to the JSON. This way I get the notifications in the background.
{
"to" : "token...",
"priority": "high",
"notification" : {
"title": "GCM TITLE",
"body" : "FROM GCM",
"badge": "1",
"sound": "default"
}
}
这篇关于GCM推送通知时,iOS应用程序是在后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!