4

Should I just let the migration continue, and then let iOS kill the app if migration takes longer than the alloted time (5 seconds) [this will generate a crash log]

Or should I abort the app? [this will also generate a crash log]

MiuMiu
  • 1,905
  • 2
  • 19
  • 28

1 Answers1

4

maybe use beginBackgroundTaskWithExpirationHandler: to ask for more time?

blub
  • 1,014
  • 7
  • 18
  • does that mean that I should perform the migration in a background thread? and if the extra time given is still not enough for the migration task, should I just let the iOS kill the app? – MiuMiu Feb 06 '13 at 00:52
  • I'm not sure how much time it is exactly atm (maybe depending on newer iOS versions, you can get that information via `backgroundTimeRemaining`), but I think the beginBackgroundTaskWithExpirationHandler should give you about 10 minutes. If that's not enough time it might be better to think about a more complex solution (running out of battery or user quitting the app manually isn't that unlikely with 5min+ tasks) – blub Feb 06 '13 at 07:28
  • I think the extra time is sufficient. But does that mean that the migration needs to be performed in the background? – MiuMiu Feb 06 '13 at 08:27
  • 1
    beginBackgroundTaskWithExpirationHandler doesn't run code on a separate "background" - thread/queue/... . It's just a way to tell the OS that you are running some task that might take some time and (if possible) should not be aborted if your app is sent to background (if it remains active: no problem). sample code: http://stackoverflow.com/questions/13574974/continue-operation-when-app-did-enter-background-on-ios – blub Feb 06 '13 at 08:47
  • did you call endBackgroundTask after the migration task? – blub Feb 06 '13 at 11:08
  • (Sorry, I have accidentally deleted my comment above. Reposting:) I have tried the beginBackgroundTaskWithExpirationHandler code. The app is given enough time in the background. But after the long-running code is finished, it still produces a crash report (app still closes). Do you have an idea on how to avoid the crash report/closing of the app? Note that this only happens in iOS 5.0. I have tried iOS 6.0, but it does not produce a crash report, and app is not closed. And yes, endBackgroundTask is called after the migration task. – MiuMiu Feb 06 '13 at 11:31
  • I don't know if there are any differences iOS5<->6 regarding this topic, but I think that whole crashing and difference thing would be worth another question with some code + crash report ;) – blub Feb 06 '13 at 13:11
  • Ok, and thanks for the answers. I am now using the beginBackgroundTaskWithExpirationHandler: method, and will post another question for the iOS 5/6 differences of the beginBackgroundTaskWithExpirationHandler: method. – MiuMiu Feb 07 '13 at 00:32