推送通知不在后台iOS中接收 [英] Push notification not receiving in background iOS

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

问题描述

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



我在方法中收到一条消息

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

当应用程序处于前台时,没有得到任何调用方法

  func application(application:UIApplication,
didReceiveRemoteNotification userInfo:[NSObject:AnyObject] ,
fetchCompletionHandler处理程序:(UIBackgroundFetchResult) - >无效)

模式。

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


[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应用程序处于前台状态

未显示系统警报



应用程序:didReceiveRemoteNotification:fetchCompletionHandler:被称为

<2>应用程序在后台



显示系统警报

应用程序:didReceiveRemoteNotification:fetchCompletionHandler:被称为



3A pp已暂停

应用程序状态更改为后台



显示系统警报



应用程序:didReceiveRemoteNotification:fetchCompletionHandler:被称为



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



显示系统警报



没有回叫


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

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

Can anyone suggest me the correct format of payload?

解决方案

use this payload

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

With content-available enabled:

1 App is in Foreground

No system alert shown

application:didReceiveRemoteNotification:fetchCompletionHandler: is called

2 App is in Background

System alert is shown

application:didReceiveRemoteNotification:fetchCompletionHandler: is called

3App is in Suspended

App state changes to Background

System alert is shown

application:didReceiveRemoteNotification:fetchCompletionHandler: is called

4 App is Not Running because killed by user

System alert is shown

No callback is called

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

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