推送通知无法正常工作,当应用程序不活跃(杀害) [英] Push notifications not working properly when the app is not active (killed)

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

问题描述

我在推送通知时遇到了问题,我正在使用Google Cloud Messaging,我的问题是我的应用使用了一些缓存数据,而我使用来自推送通知的数据刷新缓存,所以当应用程序被用户杀死(主页按钮+刷卡)并且应用程序收到推送通知时,它不会调用方法 didReceiveRemoteNotification ,因此应用程序无法访问该通知的有效内容并更新缓存的数据。



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

只有当用户点击通知并且应用程序通过应用程序: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天全站免登陆