Created
October 13, 2010 03:43
-
-
Save akiraak/623390 to your computer and use it in GitHub Desktop.
"iTunes file sharing" を利用してアプリ内のファイルをXCode無しで編集
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString* fileName = @"slideshow.txt"; | |
NSString* filePath = NULL; | |
#ifdef DISTRIBUTION | |
filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:NULL]; | |
#else | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString* documentsPath = [paths objectAtIndex:0]; | |
filePath = [NSString stringWithFormat:@"%@/%@", documentsPath, fileName]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
BOOL exist = [fileManager fileExistsAtPath:filePath]; | |
if(!exist){ | |
NSString* srcPath = [[NSBundle mainBundle] pathForResource:fileName ofType:NULL]; | |
BOOL status = [fileManager copyItemAtPath:srcPath toPath:filePath error:NULL]; | |
if(!status){ | |
ASSERT(FALSE); | |
} | |
} | |
#endif | |
NSLOG(@"%@",filePath); | |
NSString* data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; | |
NSLOG(@"%@", data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
info.plist の "Application supports iTunes file sharing" を有効にする。DISTRIBUTION のときは無効にしないとユーザーに編集されてしまうので注意。