简体   繁体   English

后台获取在模拟器中工作但在真实设备中不工作

[英]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:步骤在这里:

  1. I have enable background fetch from capabilities of app project.我已经从应用程序项目的功能中启用后台获取。

  2. 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) } } }
  3. 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.

相关问题 AVAudioPlayer在模拟器上工作但不在Real Device上工作 - AVAudioPlayer working on Simulator but not on Real Device 电话间隙-在模拟器上无法在真实设备上工作 - Phone Gap - Working on Simulator not on real device free()使用iOS Simulator,但不能在实际设备上使用 - free() working with iOS Simulator but not on real device 核心数据获取请求正在模拟器上工作,但不在设备上 - Core Data Fetch Request is working on simulator but not on the device 背景音频在iOS模拟器上可运行,但不能在设备上运行 - background audio working on iOS simulator but not device Expo 应用程序在 Expo Go 和 iOS 模拟器上工作,但在真实设备上崩溃 - Expo app working on Expo Go and iOS Simulator but crashes on real device iOS 通用应用程序链接在模拟器上工作,而不是在真实设备上 - iOS universal app links working on simulator, not on real device 为什么线性梯度在模拟器中效果很好,但在真实设备上却不行 - Why is linear gradient working well in simulator but not on real device Flutter iOS 应用程序在模拟器中完美运行,但在真实设备中无法运行 - Flutter iOS app working perfect in simulator but not in real device NSnumberFormatter在模拟器上工作,但不在设备上工作 - NSnumberFormatter working on simulator but not on device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM