ios - 后台 iOS 未收到推送通知

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

我正在通过 GCM 在我的项目中进行推送通知。我的应用程序能够在前台接收通知,但不能在后台接收通知。

我在方法中收到一条消息

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])  

当应用程序在前台但我没有收到任何对该方法的调用时

func application( application: UIApplication,
    didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
    fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void)

当应用程序处于后台模式时。

我在互联网上搜索了很长时间,才知道这是我收到的有效载荷格式的问题。我收到的有效载荷看起来像

[notification: {"body":"anything","title":"any title"}, priority: high, content_available: true, to: kcF23gblKok...., collapse_key: do_not_collapse, from: 7812....]

谁能建议我正确的有效负载格式?

最佳答案

使用这个负载

{
    "aps": {
        "alert": "Hello World",
        "sound": "default"
        "content-available" :1
    }
}

启用内容可用:

1 个应用程序在前台

没有显示系统提示

application:didReceiveRemoteNotification:fetchCompletionHandler: 被调用

2 应用在后台

显示系统警报

application:didReceiveRemoteNotification:fetchCompletionHandler: 被调用

3App处于暂停状态

应用程序状态更改为后台

显示系统警报

application:didReceiveRemoteNotification:fetchCompletionHandler: 被调用

4 应用程序未运行,因为被用户杀死

显示系统警报

没有调用回调

关于ios - 后台 iOS 未收到推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36929869/

相关文章:

iphone - 如何强制 View 呈现自身?

iOS代码覆盖率: @implementation Not Hit?

ios - 初始化程序不会在 swift 中从其父类(super class)错误中覆盖设计的初始化程序

ios - Swift 在点击按钮时完全重启动画

objective-c - 有没有办法停止所有 RestKit 处理?

iphone - 在 GridView 中按下哪个按钮

ios - 在所有 View 中使用数组变量

android - 在 Ionic 2 项目上安装 phonegap-plugin-push 后出错

android - 知道应用程序是否收到来自服务器端的通知

android - 当没有互联网连接时使用 FCM 发送推送通知