我在 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。错误操作无法完成。没有这样的文件或目录’”。
知道出了什么问题吗?
谢谢
最佳答案
您缺少文件分隔符:
... stringByAppendingString:@"/ActiveFeedsPlist.plist"];
或者,更好地,使用:
... stringByAppendingPathComponent:@"ActiveFeedsPlist.plist"];
关于iphone - Plist 不会复制到文档目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2489648/