仅当应用程序在后台时才调用静默通知回调方法 [英] Silent notification callback method called only when app is in background

查看:159
本文介绍了仅当应用程序在后台时才调用静默通知回调方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册了远程通知,它的工作状况绝对不错.现在,我正在实施静默通知.为此,我启用了后台远程通知,并且App从网络上下载了内容.

I registered remote notification and its working absolutely fine. Now I am implementing silent notification. For that, I enabled background remote notification and App downloads content from the network.

并发送,

{"aps": {"content-available": 1}}

它调用以下回调方法,但仅在应用程序处于后台时:

its calling the below callback method but only when app is in background:

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

在这种方法中,我从服务器下载了一些数据后就触发了本地通知.但是,当应用程序不在后台时,此方法根本不会调用.

And in this method, I am firing local notification after downloading some data from the server. But this method doesn't call at all when app is not in background.

推送通知上的Apple文档中a>,他们说:

In Apple docs on Push Notification, they are saying:

当收到静默通知时,iOS 在后台唤醒您的应用,以便您可以从服务器中获取新数据或进行后台信息处理."

"When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing."

理想情况下,静默远程通知应该在后台唤醒我的应用,而本地通知应该可以工作.

Ideally, silent remote notification should wake up my app in background and the local notification should work.

有什么想法吗?

推荐答案

在阅读了大量苹果文档之后,我发现如果用户强制退出应用程序,则该方法(didReceiveRemoteNotification:fetchCompletionHandler)将不会调用.

After lot of apple docs reading, I found that the method (didReceiveRemoteNotification: fetchCompletionHandler) will not invoke if user has force-quit the app.

根据书面规定,(

As written, (link) However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

这篇关于仅当应用程序在后台时才调用静默通知回调方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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