Can't figure out why my app saves session data on iPad but not on iPhone. Anyone?

I have a word game app that's ready for sale but really not so ready. When opening the game after playing it a day or so before the game state of the last session is not preserved on iPhone. But it is on iPad. How can this be as it is all the same code?

Replies

How much free space on the iPhone?


Is the iPhone jailbrk'd? On a beta?


Are both devices running the same iOs? What version(s)?


Does your game rely on a remote sign on or remote sharing/multiplayer?


How many iPhones have you tested on to confirm it isn't just that one device?

When an app is closed it goes into background after executing applicationDidEnterBackground and it can either remain in background or it can be terminated anytime by the system. (This is the difference between your two devices based on the parameters elucidated by KMT.) If it is opened from background then variables remain what they were, the app executes applicationWillEnterForeground: and continues operating from where it was when closed. If it is terminated then variables lose their value (and are uninstantiated) and the app executes didFinishLaunchingWithOptions when relaunched. If you wish to preserve your variables you need to use NSFileManager or, much easier, NSUserDefaults, to store your variables and state of play in applicationDidEnterBackground and then reset them in didFinishLaunchingWithOptions.


See this, and more, in:


https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle?language=objc

Thank you! I will work on it and get back to you with results pos or neg.


Update;


I do and have had NSUserDefault in my code that's how it is saved on iPad and iPhone 7 plus. Curiously the game state is saved on XS Max for two days or so and then reverts to initial entry point.


Looking at documentation for life cycle there's new code for ios 13 that has to do with scenes. My app has one UI on which various puzzles are selected by the user one after the other. Is that code applicable to my app?