Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akiraak/623390 to your computer and use it in GitHub Desktop.
Save akiraak/623390 to your computer and use it in GitHub Desktop.
"iTunes file sharing" を利用してアプリ内のファイルをXCode無しで編集
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);
@akiraak
Copy link
Author

akiraak commented Oct 13, 2010

info.plist の "Application supports iTunes file sharing" を有効にする。DISTRIBUTION のときは無効にしないとユーザーに編集されてしまうので注意。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment