Posts

Post not yet marked as solved
4 Replies
Thank you for the explanation eskimo,What about the "previous" iOS 12 approach ? I have created in Xcode 11 sample, trivial project which read/write from/to UserDefaults number of times performFetch is called.My point of using background fetch is for checking status of user's activation.When I debug the app it works smoothly. (i.e. Simulate Background Fetch in Xcode, or Options -> Launch Due to a background Fetch event).But It is not called on the real devices: iPhone 6, iOS 12.4, iPhone XS iOS 13.3.1here is the link:https://www.dropbox.com/s/gk63h6qmnxgeqg1/FetchTest.zip?dl=0The code is trivial, i've added "Required background modes in Info.plist, no luck 🙂.I tried running Debug & Release version it didn't work.Below is an excerpt from AppDelegate:func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. print("!!! Did finish launching count \(getCount())") application.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum) return true } func getCount() -> Int { let def = UserDefaults.standard let count = def.value(forKey: "count") as? Int ?? 0 return count } func increaseCount() -> Int { let def = UserDefaults.standard let count = getCount() def.set(count + 1, forKey: "count") def.synchronize() return count + 1 } func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { print("!!! New count \(increaseCount())") completionHandler(.newData) }Moreover, I took WWDC Background task sample code: and added there the same trivial logic count increment ( increaseCount ) logic. The code is here:https://www.dropbox.com/s/2lu7rz1lett2pzz/RefreshingAndMaintainingYourAppUsingBackgroundTasks.zip?dl=0But it doesn't work, I was opening the page with count, for a couple of times, so the system could find out, or study that I use the app, also connected the phone to the charger, but BG task doens't run. I even don't close the app, just move it into background.On Settings for the apps bg mode is enabled.It just doesn't work.