适用于iOS的GCM下行消息JSON格式 [英] GCM downstream messaging JSON format for iOS

查看:123
本文介绍了适用于iOS的GCM下行消息JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用GCM的swift / iOS9应用程序,它是通知(WIP)。



应用程序授权确定。
证书是可以的。
配置文件确定。
在苹果开发者门户网站进行开发时配置了一切。



收到通知时调用此函数。

  func application(application:UIApplication,didReceiveRemoteNotification userInfo:[NSObject:AnyObject]){
GCMService.sharedInstance()。appDidReceiveMessage(userInfo);
print(userInfo.debugDescription)
}

问题 strong>



在服务器发送以下格式时,我只能检测到前面描述的函数中的通知,并且它'有效',因为我有一个断点来检测它,否则什么也没发生

  {
registration_ids:[regId],
data:
{
to:regId,
通知:
{
sound:default,
badge:2 ,
title:anyTitle,
body:anyMessage
}
}
}

Web服务负责人为我做了这件事,并且它复制了现有的Android版本(registration_ids是否有用?)。



由于行为不是预期行为,我们在GCM网站上尝试了这一点:

{
to:regId,
content_available:true,
通知:{
body:非常棒!,
title :葡萄牙对丹麦

}

该消息创建了一个错误服务器端(GCM的无效格式?)



我们错过了一些明显的东西吗? 标题/网址:

  https://gcm-http.googleapis.com/gcm/send 
Content-Type :application / json
Authorization:key = AIzaSyZ-1u ... 0GBYzPu7Udno5aA

编辑



添加工作日志和非工作日志。

  {
registration_ids:[
regId

data:{
to:regId,
通知:{
声音:默认,
徽章:2,
title:testNotif,
body:欢迎参加Showcase Apple所有者
}
}
}



  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& regId = khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B- U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ,CamelJmsDeliveryMode = 2,CamelRedelivered = false,CamelRedeliveryCounter = 0,CamelServletContextPath = / setBeaco nEvent,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空,JMSXUserID = NULL,REGID = khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ,用户代理= Mozilla的/ 5.0(Macintosh上; Intel Mac OS X 10_11_3)AppleWebKit / 601.4.4(KHTML,如Gecko)Version / 9.0.3 Safari / 601.4.4}
BodyType字符串
Body {registration_ids:[khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B- U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ ], 要 : khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ, content_available:真实的, 通知:{ 称号: testNotif, 体: 欢迎在展示苹果所有者}}
]
Stacktrace
------------------------------------- -------------------------------------------------- ------------------------------------------------
org.apache.camel.component.http.HttpOperationFailedException:HTTP操作调用失败https://android.googleapis.com/gcm/send?custLogin=alex@cgi.com&beaconId=46589-47438&regId=khjGINhshr4: APA91bGXuzrC3tU_jkBMZGCziq IwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ with statusCode:400


$ b EDIT2



感谢Arthur的建议,通知现在不会出现错误,我收到通知。



当前格式为:

  {
to:regId,
data:{
notification :{b $ bsound:default,
badge:2,
title:testNotif,
body:welcome in the展示Apple所有者

}
}

其余问题在于如果app在后台, didReceiveRemoteNotification fetchCompletionHandler 不会收到它。
当应用程序处于前台时, didReceiveRemoteNotification 会收到它,但如果我不显示它,则不会发生任何事情。



我应该打电话给系统风格通知?如果格式正确,是否可以开箱即用?



我无法通过网络找到关于此信息。

解决方案

<

  {
to:regId ,
通知:{
sound:default,
badge:2,
title:testNotif,
body:欢迎店内Apple店主
}
}



<通过这种方式,通知由APNS处理,并以正确的格式得到完善。

I have an swift/iOS9 application using GCM for it's notifications (WIP).

Application authorisations OK. Certificates are OK. Configuration file OK. Everything is configured on the Apple's developpers portal for development.

This function is called when a notification is received.

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
  GCMService.sharedInstance().appDidReceiveMessage(userInfo);
  print(userInfo.debugDescription)
}

Problem

I can only detect a notification in the previously described function when the server send the following format, and it 'works' because i have a breakpoint to detect it, else nothing happen.

{
  "registration_ids" : ["regId"],
  "data" :
   {
      "to" : "regId",
      "notification" : 
      {
         "sound" : "default",
         "badge" : "2",
         "title" : "anyTitle",
         "body" : "anyMessage" 
      }
   }
}

The person in charge of the webservices made this for me, and it duplicated the existing Android one (Is "registration_ids" any usefull?).

Since the behaviour wasn't the expected one, we tried this from GCM website :

{ "to" : "regId", "content_available" : true, "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark" } }

The message create an error server side (invalid format for GCM?)

Do we miss something obvious?

Requests are post and headers/url:

https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

EDIT

Adding the log of the working and non working one.

{  
   "registration_ids":[  
      "regId"
   ],
   "data":{  
      "to":"regId",
      "notification":{  
         "sound":"default",
         "badge":"2",
         "title":"testNotif",
         "body":"welcome in the Showcase Apple owner"
      }
   }
}

And

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&regId=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&regId=khjGINhshr4:APA91bGXuzrC3tU_jkBMZGCziqIwA9wKv1B-U4acxy68sQxvChJQvKb187o863CzKJyop1AwhP0BNo7I2SJJiWdrtnHFC42LxcBQzOo2Ah868xPde9TBFmj_FLVG8rhyH4Yl48zuQMCJ with statusCode: 400

EDIT2

Thanks to Arthur advices, the notification leaves the server without error now, and I receive it.

Current format is :

{  
  "to":"regId",
  "data":{  
     "notification":{  
        "sound":"default",
        "badge":"2",
        "title":"testNotif",
        "body":"welcome in the Showcase Apple owner"
     }
  }
}

The remaining problem is that didReceiveRemoteNotification fetchCompletionHandler don't receives it if app is in background. Also didReceiveRemoteNotification receives it when app is foreground, but if I don't display it nothing happen.

I am supposed to call something to have the 'system style' notification? Is it ready out of the box if the format is correct?

I can't find informations about this over the web.

解决方案

Ok so, after all the only problem was the JSON format :

{  
  "to":"regId",
  "notification":{  
     "sound":"default",
     "badge":"2",
     "title":"testNotif",
     "body":"welcome in the shop Apple owner"
  }
}

This way the notification is processed by APNS and arrive refined in the correct format.

这篇关于适用于iOS的GCM下行消息JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆