静默推送通知仅在设备正在充电和/或应用程序处于前台时传送 [英] Silent push notifications only delivered if device is charging and/or app is foreground

查看:27
本文介绍了静默推送通知仅在设备正在充电和/或应用程序处于前台时传送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了静默推送通知,但我注意到了一些奇怪的行为.静默推送通知通过以下方式处理:

I have implemented silent push notifications but I have noticed some strange behaviour. The silent push notifications are handled via:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

似乎只有在设备正在充电(即连接电缆)和/或我的应用程序处于前台时才会收到无声推送消息.

The silent push messages only seem to be received if the device is charging (ie cable connected) and/or if my app is foreground.

如果我断开设备与充电器(或 Mac)的连接,则不会再收到静默推送通知除非应用程序处于前台.

If I disconnect the device from the charger (or Mac) then the silent push notifications are no longer received unless the app is foreground.

在这两种情况下,我通常都会收到非静默推送通知.

I get non-silent push notifications normally in both cases.

如果我再次插入 USB 电缆,那么我会得到预期的行为,并且无论应用是前台还是后台,都会收到静默推送通知.

If I plug in the USB cable again, then I get the expected behaviour and silent push notifications are received irrespective of whether the app is foreground or background.

我正在使用 UILocalNotification,所以我知道收到了什么.

I am using UILocalNotification so I know what is being received.

在连接设备后一切正常的事实表明我的静默推送通知配置正确,并且应用程序在 plist 等中设置了正确的后台模式.

The fact that it all works fine with the device connected suggests that my silent pushes notifications are configured correctly and that the app has the correct background modes set in the plist etc.

此行为可在运行 IOS 8 或 8.1 的 iPhone 5s、6 和 iPad 2 上重复.

This behaviour is repeatable on iPhone 5s, 6 and iPad 2 all running either IOS 8 or 8.1.

有没有其他人遇到过这种情况?应该很容易重现.为什么将设备插入充电器的简单操作会改变接收静默推送通知的能力?

Has anyone else experienced this? It should be easy to reproduce. Why should the simple act of plugging a device into a charger change the ability to receive silent push notifications?

推荐答案

我们遇到了同样的行为,并一直在试图理解为什么 iOS 决定传递一些通知而不是其他通知.

We have experienced the same behavior and have been trying to understand why iOS decides to deliver some notifications and not others.

到目前为止,我们已经制定了:

What we have worked out so far is:

  • 使用 wifi 时在后台接收消息比使用蜂窝数据时更可靠.实际上,在蜂窝网络(3g/4g)上,如果您的信号强度不够强,iOS 会收到推送消息,但不会唤醒您的应用.我们在苹果论坛上发布了关于它的信息:https://devforums.apple.com/message/1069814#1069814.我们还开了一张支持票,支持团队告诉我们将其作为错误报告提交,我们几周前就做了,现在仍在等待回音.

  • Messages will get received more reliably in background when on wifi than on cellular data. In fact, when on a cellular network (3g/4g), if your signal strength isn't strong enough, iOS receives the push message, but will not wake up your app. We posted in the apple forums about it here: https://devforums.apple.com/message/1069814#1069814. We also opened up a support ticket, and the support team told us to lodge it as a bug report, which we did a couple of weeks ago and are still waiting to hear back.

收到推送消息后,需要尽快调用fetchCompletionHandler.从技术上讲,你有 30 秒的时间来执行后台处理,但 iOS 有一个公式,你发送推送消息的频率越高,根据你在将应用程序返回到暂停状态之前处理这些消息所花费的时间,iOS 可以减少数量您的应用在未来被唤醒的次数.

When you receive a push message, you need to call the fetchCompletionHandler as soon as possible. Technically you have 30 seconds to perform background processing, but iOS has in place a formula whereby the more frequently you send push messages and depending on the amount of time you spend processing those message before returning the app to suspended state, iOS can reduce the amount of times your app gets woken up in the future.

Apple didReceiveRemoteNotification:fetchCompletionHandler: 文档:

处理完通知后,您必须立即致电在处理程序参数中阻止,否则您的应用程序将被终止.您的应用程序有长达 30 秒的挂钟时间来处理通知并调用指定的完成处理程序块.在练习,你应该在完成后立即调用处理程序块处理通知.系统跟踪经过的时间、电量您的应用程序后台下载的使用情况和数据成本.应用程序处理推送通知时使用大量电量可能不会总是早早醒来处理未来的通知.

As soon as you finish processing the notification, you must call the block in the handler parameter or your app will be terminated. Your app has up to 30 seconds of wall-clock time to process the notification and call the specified completion handler block. In practice, you should call the handler block as soon as you are done processing the notification. The system tracks the elapsed time, power usage, and data costs for your app’s background downloads. Apps that use significant amounts of power when processing push notifications may not always be woken up early to process future notifications.

在我们的测试中,我们一直在向我们的应用发送频繁的静默推送通知(每 10 到 30 秒).在我们将其重新休眠之前,该应用程序会唤醒大约 3 秒钟.随着时间的推移,我们肯定注意到我们的应用程序被唤醒的频率下降到 iOS 只会每 15 到 30 分钟唤醒一次应用程序的程度.因此,似乎存在某种衰减/节流公式,但我们找不到任何关于它究竟如何工作的文档.我们已向 Apple 请求了此公式和变量作为支持请求,但他们说您请求的信息不公开",并再次要求我们提交错误报告.

In our testing, we have been sending frequent silent push notifications to our app (every 10 - 30 seconds). And the app is awake for about 3 seconds before we put it back to sleep. We have definitely noticed over time a degradation in the frequency in which our app gets woken up to the point where iOS will only wake up the app every 15 - 30 minutes. So there seems to be some sort of decay/throttling formula in place, but we cannot find any documentation on how it exactly works. We have requested this formula and the variables from apple as a support request, but they said "The information you are requesting is not publicly available" and again asked us to file a bug report.

那么,希望这有帮助吗?我们仍在努力学习更多自己,这就是我发现这个问题的原因:)

So, hopefully this is helpful? We are still trying to learn more ourselves which is why I found this question :)

这篇关于静默推送通知仅在设备正在充电和/或应用程序处于前台时传送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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