Recently while doing some debug testing for pushKit VOIP events due to iOS 13 changes around push events waking the app, and while profiling the app in instruments, I came across that it appears that iOS 13 is not suspending my threads the normal 30 seconds or so after the app has been backgrounded. while testing from xcode 10.3 on an iOS 12.4.2 iPhone 6 and iPhone 5s, i saw behavior as i would expect, with a consistent halting of the threads after approx 30 seconds in the background. When i side load the same build from xcode 10.3 archived using a developer release build to an iOS 13.1.3 iPhone X and iPhone 8 device i saw it behave odd. When backgrounding, the threads kept running indefinately, and never suspended.
To rule out something strange with my setup, i build a brand new app, in xcode 10.3 and added a simple run loop callback method from the app delegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
wastetime()
return true
}
func wastetime() {
delay(0.5) { [weak self] in
print("wasting time")
let _ = malloc(300000)
self?.wastetime()
}
}
lazy var dispatchQueue: DispatchQueue = DispatchQueue(label: "test queue")
func delay(_ delay: Double, closure: @escaping () ->()) {
let deadline = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
dispatchQueue.asyncAfter(deadline: deadline) {
DispatchQueue.main.async(execute: closure)
}
}
I then ran this on an iOS 12.4.2 device and got the expected behavior. ran it on an iOS 13.1.3 device, and got the non suspending behanvior. I did archive builds signed with a developer cert to rull out any debuging. I then tried in xcode 11 doing the same process and seeing the same behavior where the iOS 12 device suspended its threads and the iOS 13 device did not.
Did something fundametally change with how iOS 13 is suspending applications? This seems like either a really bad bug, or something must have changed fundamental to the understanding of background and app suspension in iOS 13 that does not match any documentation that I can find. ALL documentaton seems to be aligned with the iOS 12 behavior, which is what I expect. iOS 13 behanvir is bad for battery life, and appears to be causing our app to be bing killed bucause it is using to much CPU In the background due to it not being suspended. Is anyone else seeing this behavior? Am I missing something?
Termination Description: SPRINGBOARD, scene-create watchdog transgression: application<redacted>:373 exhausted CPU time allowance of 4.80 seconds | ProcessVisibility: Background | ProcessState: Running | WatchdogEvent: scene-create | WatchdogVisibility: Background | WatchdogCPUStatistics: ( | "Elapsed total CPU time (seconds): 7.260 (user 7.260, system 0.000), 69% CPU", | "Elapsed application CPU time (seconds): 5.230, 50% CPU" | )
Triggered by Thread: 0