Objc writes data to the plist file of the iOS real machine

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.