1

I used below code to determine how many time remained to suspending my app. First I called UIApplication.shared.beginBackgroundTask but after backgroundTimeRemainingreached 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.")
            }
        }
    }
}
rick
  • 1,009
  • 2
  • 10
  • 28
  • 3
    Are you running your app from Xcode? App's are not terminated when you run through Xcode. – rmaddy May 28 '18 at 05:54
  • Yes I'm running from Xcode. I didn't know. Thanks. Is there any way that I force Xcode to run app in real situation? – rick May 28 '18 at 06:13

0 Answers0