When PerformFetch
(application:performFetchWithCompletionHandler:
) is called in the background you have ~30 seconds to return from that method or that process will be terminated.
If terminated, your code will never enter the finally
block with your PerformFetch
override, nor will WillTerminate
(applicationWillTerminate:
) be called. This will be treated by iOS as an UIBackgroundFetchResult.Failed
since PerformFetch
did not return.
If you flagged the start of some block of code via BeginBackgroundTask
(beginBackgroundTaskWithName:expirationHandler:
) within the PerformFetch
then yes, the expirationHandler
is called when the OS terminates the PerformFetch
.