使用GCM进行iOS推送通知

时间:2016-05-04 12:18:57

标签: ios push-notification google-cloud-messaging

我正在使用GCM向iOS应用程序发送远程通知,在前台和后台都收到通知,但在后台通知没有在应用程序图标上显示带声音和徽章编号的横幅,我在哪些字段应该添加,我应该添加它们

2 个答案:

答案 0 :(得分:1)

我试了一下,效果很好。这是它的工作原理:

  • 您可以在Google控制台创建应用条目。
  • 上传在创建向导中认证的开发和生产。
  • 您必须上传两者并按照docs
  • 中的步骤操作

逻辑的工作原理如下:

  • 我们像往常一样从apns请求设备令牌。
  • 然后我们将该令牌发送到提供api的gcm服务。
  • 然后gcm发回另一个令牌。
  • 我们将该令牌发送到应用服务器。
  • 应用服务器可以使用该令牌发送通知。

很酷的功能。 GCM for iOS有一些很酷的功能:

  • 根据特定主题订阅通知。
  • 忽略他人。
  • 将通知发送到应用内的其他设备。

更新:Google现在有一个大写字母G.

如果你想试试谷歌示例应用。只是 void

答案 1 :(得分:0)

如果您在后台接收远程通知。可能您的content-available = 1字段已经在json有效负载中,因此请向您的设备发送本地通知和横幅以执行您想要的所有其他操作。

let localNotification = UILocalNotification()
localNotification.soundName = UILocalNotificationDefaultSoundName //If you want an alert sound.
localNotification.alertBody = "You received notification" //Put your notification message here
localNotification.applicationIconBadgeNumber += 1 //Change what the badge number should be

UIApplication.sharedApplication().presentLocalNotificationNow(localNotification)

放置此代码的一个地方是func,并在收到远程通知时调用它。