I have created an iOS native app using Swift 5.0, which internally fetch data from the server using background fetch feature of iOS if the App is running in background mode.
Background fetching is working properly in Simulator and http request reaches in the server. But background fetches not at all working in the real device (iPad Air & iOS 12.2).
Please help me to resolve.
AppDelegate.swift code
Background fetching is working properly in Simulator and http request reaches in the server. But background fetches not at all working in the real device (iPad Air & iOS 12.2).
I have enabled Background fetch of 'Background modes' under "Capabilities" on the target in Xcode.
Configured minimum background fecth interval and 'performFetchWithCompletionHandler' method in AppDelegate.swift class
I manually verified that real device has Background Refresh is enabled in App's settings.
Please help me to resolve.
AppDelegate.swift code
Code Block import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15)) return true } func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { if let url = URL(string: "http://192.168.225.24:80/product") { URLSession.shared.dataTask(with: url, completionHandler: { (data, respone, error) in guard let `data` = data else { completionHandler(.failed); return } let result = String(data: data, encoding: .utf8) print("performFetchWithCompletionHandler result: \(String(describing: result))") completionHandler(.newData) }).resume() } } }