4

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]);
}

エラー「***キャッチされない例外のためにアプリを終了します'NSInternalInconsistencyException'、理由:'Plistのコピーに失敗しました。エラー操作を完了できませんでした。そのようなファイルまたはディレクトリはありません'」というエラーがコンソールに表示されます。

何が悪いのか分かりますか?

ありがとう

4

1 に答える 1

10

ファイルセパレータがありません:

... stringByAppendingString:@"/ActiveFeedsPlist.plist"];

または、より良い方法として、次を使用します。

... stringByAppendingPathComponent:@"ActiveFeedsPlist.plist"];
于 2010-03-22T02:26:01.657 に答える