I used below code to determine how many time remained to suspending my app. First I called UIApplication.shared.beginBackgroundTask
but after backgroundTimeRemaining
reached zero my app was not terminated.
In another scenario I didn't call UIApplication.shared.beginBackgroundTask
but again my app has 180 seconds to run in background and after backgroundTimeRemaining
reached zero, my app was not terminated again.
So can it be said that there is no force to call beginBackgroundTask
to get more time? Or it depends on system situation?
My main question is why system didn't terminate my app after backgroundTimeRemaining
reached zero, while I didn't call endBackgroundTask
?
func applicationDidEnterBackground(_ application: UIApplication) {
DispatchQueue.main.async {
let app = UIApplication.shared
while app.backgroundTimeRemaining > 0 {
print(app.backgroundTimeRemaining, " seconds to suspend.")
}
}
}
}