当应用程序处于非活动状态(被终止)时,推送通知无法正常工作 [英] Push notifications not working properly when the app is not active (killed)

查看:38
本文介绍了当应用程序处于非活动状态(被终止)时,推送通知无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在推送通知方面遇到问题,我正在使用 Google Cloud Messaging,

我的问题是我的应用程序使用一些缓存数据,我使用来自推送通知的数据刷新该缓存,因此当应用程序被用户杀死(主页按钮 + 向上滑动)并且应用程序收到一个推送通知不会调用方法 didReceiveRemoteNotification,因此应用程序无法访问该通知的有效负载并更新缓存数据.

那么,有没有办法实现这一目标?

仅当用户点击通知并且应用通过application:didFinishLaunchingWithOptions 方法获取通知时?

如果用户通过单击应用程序图标打开应用程序,我无法获得通知的有效负载?

PD:如果应用在前台或后台(没有被杀死),它可以完美运行

解决方案

如果您希望您的应用即使在被杀死时也能收到推送通知,请添加键 "content-available":"1" 到推送有效负载.

我必须说,我真的不明白为什么操作系统不让我的应用程序在我的应用程序死后静默推送到达时唤醒它.那有什么意义???

I'm facing a problem with push notifications, I'm using Google Cloud Messaging,

My problem is that my app works with some cached data, and I refresh that cache with the data coming from push notificacions, so when the app is killed by the user (home button + swipe-up) and the app receive a push notification it doesn't call the method didReceiveRemoteNotification, so the app can't access to the payload of that notification and update the cached data.

So, is there a way to achieve this?

Only when the user taps the notifications and the app gets it through the application:didFinishLaunchingWithOptions method?

If the user opens the app by clicking the application icon I can't get the notificaton's payload?

PD: If the app is in foreground or background (not killed) it works perfectly

解决方案

If you wish your app to receive the push notification even when it is killed, add the key "content-available":"1" to the push payload.

Look here

EDIT: After digging some more, I found out that silent push (e.g content-available:1), does not wake the app if it was killed by the user:

However, the system does not automatically launch your app if the user has force-quit it

I must say, I can't really understand why the OS does not let my app wake up when silent push arrives when it's dead. What's the point then???

这篇关于当应用程序处于非活动状态(被终止)时,推送通知无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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