plistのドキュメントディレクトリにコピーしません。
-
21-09-2019 - |
質問
私はXcodeで私のリソース・グループ内のplistファイルを持っています。私は、アプリの起動時にマイドキュメントディレクトリにこれをコピーしようとしています。私は(sqliteのチュートリアルから取られた)次のコードを使用しています:
BOOL success;
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"ActiveFeedsPlist.plist"];
success = [fileManager fileExistsAtPath:filePath];
if (success) return;
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"ActiveFeedsPlist.plist"];
success = [fileManager copyItemAtPath:path toPath:filePath error:&error];
if (!success) {
NSAssert1(0, @"Failed to copy Plist. Error %@", [error localizedDescription]);
}
しかしコンソールで:私は「『PLISTのコピーに失敗しましたエラー操作を完了できませんでしたそのようなファイルまたはディレクトリ。』キャッチされない例外により 『NSInternalInconsistencyException』、理由にアプリを終了***」のエラーを与えています。
何が間違っている任意のアイデア?
おかげ
解決
あなたはファイル区切りを逃している。
... stringByAppendingString:@"/ActiveFeedsPlist.plist"];
または、より良い、使用します:
... stringByAppendingPathComponent:@"ActiveFeedsPlist.plist"];
所属していません StackOverflow