fetchCompletionHandler

fetchCompletionHandler

本文介绍了在后台iOS中未收到推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am doing push notification in my project through GCM. My Application is able to receive notification in foreground but not in background.

我在方法内收到一条消息

I receive a message inside the method

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

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

when the application is in foreground but I am not getting any call to the method

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

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

when the application in background mode.

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

I had a long search in Internet and came to know that it's the problem with the payload format I receive. The payload I received looks like

[通知:{"body":"anything","title":"any title"},优先级:高,content_available:true,至:kcF23gblKok....,collapse_key:do_not_collapse,来自:7812....]

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

Can anyone suggest me the correct format of payload?

推荐答案

使用这个payload

use this payload

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

启用内容可用:

1 个应用程序在前台

未显示系统警报

application:didReceiveRemoteNotification:fetchCompletionHandler: 被调用

2 应用程序在后台

显示系统警报

application:didReceiveRemoteNotification:fetchCompletionHandler: 被调用

3App 处于暂停状态

3App is in Suspended

应用状态更改为后台

显示系统警报

application:didReceiveRemoteNotification:fetchCompletionHandler: 被调用

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

4 App is Not Running because killed by user

显示系统警报

不调用回调

这篇关于在后台iOS中未收到推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 22:20