0

If I have a function in PerformFetch to do background fetching in iOS.

I have "finally" statement inside the PerformFetch. When the background fetch expired will the finally block get call as well. Or will it go straight to the ExpirationHandler block to do the clean up before the application killed by the OS

LittleFunny
  • 8,155
  • 15
  • 87
  • 198

1 Answers1

0

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.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165