我有一个使用GCM的swift / iOS9应用程序用于通知(WIP)。
申请授权确定。 证书没问题。 配置文件OK。 所有内容都在Apple的开发人员门户网站上进行配置。
收到通知时会调用此函数。
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
GCMService.sharedInstance().appDidReceiveMessage(userInfo);
print(userInfo.debugDescription)
}
问题
当服务器发送以下格式时,我只能在前面描述的函数中检测到通知,并且它“有效”,因为我有一个断点来检测它,否则什么都不会发生。
{
"registration_ids" : ["regId"],
"data" :
{
"to" : "regId",
"notification" :
{
"sound" : "default",
"badge" : "2",
"title" : "anyTitle",
"body" : "anyMessage"
}
}
}
网络服务的负责人为我做了这个,它复制了现有的Android服务器(“registration_ids”是否有用?)。
由于行为不是预期的行为,我们在GCM网站上尝试了这个:
{ “to”:“regId”, “content_available”:是的, “通知”:{ “身体”:“很棒的比赛!”, “头衔”:“葡萄牙与丹麦” } }
该消息是否为服务器端创建错误(GCM格式无效?)
我们是否错过了一些明显的内容?
请求是post和headers / url:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
修改
添加工作日志和非工作日志。
{
"registration_ids":[
"regId"
],
"data":{
"to":"regId",
"notification":{
"sound":"default",
"badge":"2",
"title":"testNotif",
"body":"welcome in the Showcase Apple owner"
}
}
}
和
Exchange[
Id ID-FR-LIL-D00184-54996-1457452459441-0-5
ExchangePattern InOnly
Headers {Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, Accept-Encoding=gzip, deflate, Accept-Language=fr-fr, Authorization=key=AIzaSyAB_E2Op0GqShCmCmh_6ZxnwrFKoXOaIHU, beaconId=46589-47438, breadcrumbId=ID-talend2-48271-1456928459992-11-173, Cache-Control=max-age=0, CamelHttpMethod=POST, CamelHttpPath=, CamelHttpQuery=custLogin=alex@cgi.com&beaconId=46589-47438®Id=khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ, CamelJmsDeliveryMode=2, CamelRedelivered=false, CamelRedeliveryCounter=0, CamelServletContextPath=/setBeaconEvent, Connection=keep-alive, Content-Type=application/json, custLogin=, dateEvent=20160308172331, deviceType=ios, DNT=1, Host=192.168.1.239, JMSCorrelationID=null, JMSDeliveryMode=2, JMSDestination=queue://Q.NOTIFIER, JMSExpiration=0, JMSMessageID=ID:FR-LIL-D00184-64570-1457442695117-1:52:1:1:1, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=null, JMSTimestamp=1457454212345, JMSType=null, JMSXGroupID=null, JMSXUserID=null, regId=khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ, User-Agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4}
BodyType String
Body {"registration_ids":["khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ"],"to":"khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ", "content_available": true, "notification":{"title": "testNotif","body": "welcome in the Showcase Apple owner" }}
]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking https://android.googleapis.com/gcm/send?custLogin=alex@cgi.com&beaconId=46589-47438®Id=khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ with statusCode: 400
EDIT2
感谢Arthur的建议,通知现在离开服务器没有错误,我收到了。
目前的格式是:
{
"to":"regId",
"data":{
"notification":{
"sound":"default",
"badge":"2",
"title":"testNotif",
"body":"welcome in the Showcase Apple owner"
}
}
}
剩下的问题是如果app在后台,didReceiveRemoteNotification fetchCompletionHandler
不会收到它。
当应用程序是前台时,didReceiveRemoteNotification
也会收到它,但如果我不显示它,则不会发生任何事情。
我应该打电话给'系统风格'通知吗?如果格式正确,它是否已经开箱即用?
我无法通过网络找到有关此内容的信息。
答案 0 :(得分:0)
因此,当您使用您提到的第一种格式时,您会收到通知(应用程序在断点处停止)?我唯一的想法是,当您收到通知时,您的应用程序可能处于前台?它应该在后台或关闭,否则你不会注意到任何事情。
答案 1 :(得分:0)
好的,毕竟唯一的问题是JSON格式:
{
"to":"regId",
"notification":{
"sound":"default",
"badge":"2",
"title":"testNotif",
"body":"welcome in the shop Apple owner"
}
}
这样,通知由APNS处理,并以正确的格式精确到达。