[英]Background fetch working in simulator but not working in real device
I am calling API to get data and show local push based on the response of API so I am using background fetch
service of Apple which is introduce in iOS 13
and above.我正在调用 API 来获取数据并根据 API 的响应显示本地推送,所以我使用的是 Apple 的background fetch
服务,该服务在iOS 13
及更高版本中引入。
But when try to test this scenario in simulator and it works fine but when I checked this app in real device then it is not working and lost the connection when it tries to call api in background.但是当尝试在模拟器中测试这个场景并且它工作正常但是当我在真实设备中检查这个应用程序时它没有工作并且当它试图在后台调用 api 时失去连接。
I am not killing my app from device just put back by click on home button.我没有从设备中杀死我的应用程序,只是通过单击主页按钮放回。
I am not sure why it is not running in real device.我不确定为什么它不在真实设备中运行。
What I did till now.我到目前为止所做的。 Steps are here:步骤在这里:
I have enable background fetch from capabilities of app project.我已经从应用程序项目的功能中启用后台获取。
then I have added this code in AppDelegate
然后我在AppDelegate
中添加了这段代码
extension AppDelegate { func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("Bg Fetch from App Delegate 1") DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { BroadCastManager.sharedInstance.fetchNewDataWithCompletionHandler(completionHandler: completionHandler) } } }
This will call one method from service class where one API will be call and then based on response api it will fire one local push.这将从服务 class 调用一种方法,其中将调用一个 API,然后根据响应 api 它将触发一个本地推送。
So here problem is that when API is call in real device and app is in background then i am getting below error.所以这里的问题是,当 API 在真实设备中调用并且应用程序在后台时,我会遇到错误。
error screenshot.错误截图。
The code you have is iOS12 and earlier.您拥有的代码是 iOS12 及更早版本。 Try the new process.尝试新流程。 I just gave an example (my app's working code) here:我只是在这里举了一个例子(我的应用程序的工作代码):
BGAppRefreshTask Background Task Not Executing BGAppRefreshTask 后台任务未执行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.