Objc writes data to the plist file of the iOS real machine
However, this does not work for the real machine, because in the real machine environment, the Resources folder of the App in Xcode is not writable. therefore, when the App runs for the first time, we need to put the data that needs to be modified and saved for a long time under the Document directory:
// Initialize the map data file in the Document directory, because the file in this directory can be written and can be permanently saved + (void) initDataFile {NSString * docPath = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) [0]; // get the target file path sMapInfoInDocPath = [docPath stringByAppendingPathComponent: @ "MapInfo. plist "]; NSFileManager * fm = [NSFileManager defaultManager]; // if the target file does not exist, it is the first time the App is running. Copy the modifiable data file to the target path. if (! [Fm fileExistsAtPath: sMapInfoInDocPath]) {NSError * error = nil; // obtain the source file path NSString * srcPath = [[NSBundle mainBundle] pathForResource: MAP_INFO_FILE ofType: @ "plist"]; if (! [Fm copyItemAtPath: srcPath toPath: sMapInfoInDocPath error: & error]) {CCLOG (@ "ERR: copy file failed: % @", error );}}}
Note: After an App is deleted, all files previously stored in the Document directory of the App will be deleted.