I have copied the following word-for-word from a book to obtain a save path for archiving using NSCoding:
This is followed by calling this method:
This successfully saves when it is run in the simulator (when I reopen the app after closing it fully, all objects that were previously in the array dataBaseArray reappear). When I run the app on the iPhone, it doesn't work.
I think it is maybe something to do with the path that is obtained on the iPhone. I changed the itemArchivePath method to the following to see if that worked:
This again works in the simulator but not on the iPhone.
For information, the screenshot shows the path that is obtained when I step through the code whilst running on the iPhone.
Does anyone know why this works in the simulator but not on the device?
Thank you.
Code:
-(NSString *)itemArchivePath {
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
return [documentDirectory stringByAppendingPathExtension:@"projects.archive"];
}
This is followed by calling this method:
Code:
-(BOOL)saveChanges {
NSString *path = [self itemArchivePath];
return [NSKeyedArchiver archiveRootObject:dataBaseArray toFile:path];
}
This successfully saves when it is run in the simulator (when I reopen the app after closing it fully, all objects that were previously in the array dataBaseArray reappear). When I run the app on the iPhone, it doesn't work.
I think it is maybe something to do with the path that is obtained on the iPhone. I changed the itemArchivePath method to the following to see if that worked:
Code:
-(NSString *)itemArchivePath {
NSString *documentDirectory = [[NSBundle mainBundle]bundlePath];
return [documentDirectory stringByAppendingPathExtension:@"projects.archive"];
}
This again works in the simulator but not on the iPhone.
For information, the screenshot shows the path that is obtained when I step through the code whilst running on the iPhone.
Does anyone know why this works in the simulator but not on the device?
Thank you.
Attachments
Last edited: