0

I am trying to figure out some logic in my iOS application delegate. I want to perform some actions in applicationDidEnterBackground and undo them in applicationWillEnterForeground, as suggested. But I want to make sure that, unless the app is terminated, applicationWillEnterForeground is always called after applicationDidEnterBackground. I know that this is generally the case, but I know that there are always fringe cases (authorizations, other interruptions like phone calls, notifications). I think that I have checked most cases and found that applicationWillEnterForeground will always be called to counter applicationDidEnterBackground but I want to see if there are any cases that I am missing where this is not the case.

SAHM
  • 4,078
  • 7
  • 41
  • 77

1 Answers1

0

Set a Boolean value in the user defaults when you enter the background. Then, when you re-enter the foreground check the value of that Boolean to determine whether or not it was set properly. Either way, always set the Boolean to false when returning to the foreground.

  • Thanks, I do understand how to check this in a particular case, but I am trying to find out if there are any cases that I have NOT thought about (and therefore cannot check) – SAHM Nov 16 '14 at 14:00
  • If you are restricted to using the app delegate then the only other indicator would be the applicationWillTerminate: method being called. If you can include crashlytics in your app then you can implement their delegate methods to determine when that has been restarted following a crash. Hope this helps. – Christopher Shireman Nov 16 '14 at 17:03
  • Thanks.. I'm not exactly sure what you are saying though. There is no crash. I am just trying to be thorough in my planning and understanding of what is happening within my app. – SAHM Nov 16 '14 at 20:54
  • Sorry if I was confusing. I only mentioned craslytics because it seemed like you needed to know when the app was restarted, and craslytics allows you to do that even after a crash. – Christopher Shireman Nov 16 '14 at 23:25
  • No problem. I don't need to know when the app is restarted, only that when I *do* something, it will most definitely be *undone* no matter which way I return to the app. Thanks for the answer – SAHM Nov 18 '14 at 06:40