简体   繁体   中英

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.

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.

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

    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.

So here problem is that when API is call in real device and app is in background then i am getting below error.

error screenshot.

在此处输入图像描述

The code you have is iOS12 and earlier. Try the new process. I just gave an example (my app's working code) here:

BGAppRefreshTask Background Task Not Executing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM