2012-01-21 8 views
1

私の主なアプリケーションバンドルに私のアプリからアップデートしたいplistファイルがあります。ここで私が使用しているコードは、plistは更新されていないようです。コードが間違っているのですか、別の問題がありますか?plistファイルの内容はどのように上書きできますか? (iPhone/iPad)

// Data 
NSMutableDictionary *data = [[NSMutableDictionary alloc] init]; 
[data setObject:self.someValue forKey:@"Root"]; 

// Save the logs 
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"plist"]; 
[data writeToFile:filepath atomically:YES]; 

誰かが私を助けてくれますか?

+1

を助け、私のアプリケーションの一つで

//get file paths NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [documentPaths objectAtIndex:0]; NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"document.plist"]; NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; NSString *bundlePlistPath = [bundlePath stringByAppendingPathComponent:@"bundle.plist"]; //if file exists in the documents directory, get it if([fileManager fileExistsAtPath:documentPlistPath]){ NSMutableDictionary *documentDict = [NSMutableDictionary dictionaryWithContentsOfFile:documentPlistPath]; return documentDict; } //if file does not exist, create it from existing plist else { NSError *error; BOOL success = [fileManager copyItemAtPath:bundlePlistPath toPath:documentPlistPath error:&error]; if (success) { NSMutableDictionary *documentDict = [NSMutableDictionary dictionaryWithContentsOfFile:documentPlistPath]; return documentDict; } return nil; } 

希望を、それをやってみましょう最初にディレクトリ。 –

+0

私はこれを知らなかった。あなたの提案を実装する方法をアドバイスできますか? –

答えて

3

IOSはバンドルされたファイルへの書き込みを制限します。書き込み可能なplistが必要な場合は、アプリのDocumentsフォルダにコピーしてそこに書き込む必要があります。ここで

+0

お手数をおかけしていただきありがとうございます。どうすればよいですか? –

+0

http://stackoverflow.com/questions/3238143/iphone-ios-copying-files-from-main-bundle-to-documents-folder-causes-crashをご覧ください。 –

+0

ありがとうございました@JoachimIsaksson!私はこの1つにこだわっていた。 iOSがアプリケーションにバンドルされているファイルを上書きすることができるように見えますが、アプリケーションの再起動ではすべての変更がなくなりました。私はかなり困惑した。 – javajavajavajavajava

2

は、私は、これは、あなたの文書にコピーする必要があると思いますが、あなたのアプリケーションバンドルには何も更新することはできません

関連する問題