APNS:当应用程序在后台运行时,didReceiveRemoteNotification:fetchCompletionHandler未运行(除非xcode正在调试) [英] APNS: didReceiveRemoteNotification:fetchCompletionHandler did not run when app is in background (unless xcode is debugging)

查看:448
本文介绍了APNS:当应用程序在后台运行时,didReceiveRemoteNotification:fetchCompletionHandler未运行(除非xcode正在调试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行iOS 8.1的iPad 2中遇到有关APNS的问题.我在Google上搜索了几天,并尝试了所有可以找到的解决方案.但是我似乎无法解决这个问题.

I have this problem regarding APNS in my iPad 2 running iOS 8.1 . I searched on Google for a few days and tried every solution that I can find. However I cant seem to solve this problem.

我做了什么:

  1. 已启用的功能:远程通知,后台获取
  2. 我在aps有效负载中有"content-available = 1".
  3. 我在didReceiveRemoteNotification:fetchCompletionHandler中使用了NSLog(),因此我可以在设备日志中清楚地看到该方法是否被触发

我想做什么:

我想在后台收到APNS时执行网络请求.我相信我可以使用beginBackgroundTaskWithExpirationHandler和其他东西很好地处理这一部分.但是,在调查中,我发现问题是由于app处于后台状态时未运行didReceiveRemoteNotification:fetchCompletionHandler所致.

I want to perform network request when I receive the APNS in background. I believe I can handle that part well using beginBackgroundTaskWithExpirationHandler and stuff. However, going down the investigation I found that the problem is due to didReceiveRemoteNotification:fetchCompletionHandler not been run when app is in background state.

问题:

didReceiveRemoteNotification:fetchCompletionHandler可以在应用程序处于前台时触发.但这是仅在xcode仍在调试应用程序时在后台触发..这意味着,如果拔下电缆(调试会话已结束),它将无法再触发.如果我重新插回电源,也一样.无响应.

didReceiveRemoteNotification:fetchCompletionHandler can trigger when app is in foreground. But it is ONLY triggered in background when xcode is still debugging the app. Which means if I unplug the cable (the debugging session is over), it cannot trigger anymore. Same thing if I replug it back in. No response.

但是,与此同时,我仍然可以像在设备日志中看到的那样,收到带有警报正文和声音的APNS(尽管该方法仍未触发).

However, at the same time, I can still receive APNS with alert body and sound (although the method is still not triggered) as I see in the Device Log.

我尝试了无声"推送通知的所有组合:声音=",警报=",等等.但是似乎没有任何效果.这里的专业人士有帮助吗?

I tried every combination of "silent" push notification: sound = "", alert = "", etc. But nothing seems to work. Any help from the pros here?

谢谢.

推荐答案

再次检查是否已启用后台应用刷新".在旅行途中将其关闭后,我遇到了一段时间.

Double check that Background App Refresh is turned on. I ran into this for a while after turning it off while traveling.

此外,您不必在didReceiveRemoteNotification:fetchCompletionHandler内部使用后台任务,因为它已经在后台运行.完成网络请求后,只需确保调用适当的完成处理程序即可.

Also, you shouldn't need to use a background task inside of the didReceiveRemoteNotification:fetchCompletionHandler as it is already running in the background. Just make sure to call the appropriate completion handler when you're done with your network request.

最后,由于常规通知不会唤醒您的应用并执行代码,因此不会在常规(非静默)通知中调用didReceiveRemoteNotification:fetchCompletionHandler.

Finally, didReceiveRemoteNotification:fetchCompletionHandler will not be called on a regular (non-silent) notification because regular notifications do not wake your app and execute code.

另一个令人费解的奇怪事情是通知框架数据中的优先级-

Another weird obscure thing to check is the priority in the notification frame data - link to Apple Documentation - command F for 'priority' for the details. When I was doing this my Ruby gem that built the notification was using 10 by default, which is supposedly not allowed if you are only using 'content-available' and nothing else. Things got busy at work and I never got to test this using a priority of 5, but it may help.

这篇关于APNS:当应用程序在后台运行时,didReceiveRemoteNotification:fetchCompletionHandler未运行(除非xcode正在调试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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