I have a simple word game that I just put up on the App Store. The games progress is saved from session to session on my iPad and iPhone 7 plus but not on iPhone XS Max.
So, the code is working for saving game progress except for XS Max. Other XS Max phones as well as mine.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#if 0
NSArray *puzzlesArray;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *docFile = [documentsDirectory stringByAppendingPathComponent:@"Puzzles.plist"];
puzzlesArray = [[NSArray alloc] initWithContentsOfFile:docFile];
if (!puzzlesArray) {
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"puzzles" ofType:@"plist"];
puzzlesArray = [[NSArray alloc] initWithContentsOfFile:thePath];
}
#endif
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] postNotificationName:@"applicationWillResignActive" object:self];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] postNotificationName:@"applicationDidEnterBackground" object:self];
}
Both of those with appropriate code in Game Controller.
- (BOOL)writeApplicationData:(NSData *) data toFile:(NSString *)docFile {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return (NO);
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:docFile];
return ([data writeToFile:appFile atomically:YES]);
}
- (void)applicationWillTerminate:(UIApplication *)application {
#if 0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *docFile = [documentsDirectory stringByAppendingPathComponent:@"puzzles.plist"];
NSData *pData = [[[NSData alloc] initWithContentsOfFile:docFile] autorelease];
[self writeApplicationData:pData toFile:docFile];
#endif // if 0
}
- (NSData *)applicationDataFromFile:(NSString *)docFile {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:docFile];
NSData *pData = [[NSData alloc] initWithContentsOfFile:appFile];
return (pData);
}
@end
I have no code in applicationDidEnterBackground
or applicationWillEnterForeground
.
For the XS Max the games are saved for two days or so before reverting back to entry point.