【发布时间】:2016-04-29 04:58:16
【问题描述】:
我正在通过 GCM 在我的项目中进行推送通知。我的应用程序能够在前台接收通知,但不能在后台接收。
我在方法中收到一条消息
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
当应用程序在前台,但我没有收到对该方法的任何调用
func application( application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void)
当应用程序处于后台模式时。
我在 Internet 上进行了长时间的搜索,然后才知道这是我收到的有效负载格式的问题。我收到的有效载荷看起来像
[通知:{“body”:“anything”,“title”:“any title”},优先级:高,content_available:true,至:kcF23gblKok..,collapse_key:do_not_collapse,来自:7812.. ..]
谁能建议我正确的payload格式?
【问题讨论】:
-
如果推送在应用程序未运行时到达,则不执行任何代码。见stackoverflow.com/questions/11153631/…
-
我的确切问题是当应用程序进入后台模式时我根本没有收到任何消息。在前台模式下,所有消息都成功接收。
-
你开启后台模式功能了吗?
-
试试这个链接它对你很有帮助stackoverflow.com/questions/31109514/…
-
可能重复。在此thread 中解决了让 GCM 在 iOS 设备的后台工作的问题
标签: ios swift push-notification google-cloud-messaging