我試圖從應用程序包複製一個plist文件,該文件從應用程序包複製到文檔目錄,但只有ios8中的消息「NSInternalInconsistencyException」失敗,原因如下: '操作無法完成(可可錯誤4)'。'「。它在ios7中正常工作。請指導可能的原因。未能複製ios8中文檔目錄中的可寫plist文件
//To get the plist file path within app
-(NSString *)ogPath
{
NSString *str = [[NSBundle mainBundle] bundlePath];
str = [str stringByAppendingPathComponent:@"configUrl.plist"];
return str;
}
//To get the plist file path within documents directory
-(NSString *)documentPath
{
NSString *str = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
str = [str stringByAppendingFormat:@"/Documents/configUrl.plist"];
return str;
}
//to copy plist file within app to documents directory
-(void)copytheplistfile
{
NSString *plistpath = [self ogPath];
NSString *docpath = [self documentPath];
NSFileManager *file = [NSFileManager defaultManager];
BOOL fileexist = [file fileExistsAtPath:docpath];
if(!fileexist)
{
NSError *err;
BOOL copyResult=[file copyItemAtPath:plistpath toPath:docpath error:&err];
NSLog(@"error:%@",[err localizedDescription]);
if(!copyResult)
NSAssert1(0, @"Failed to create writable plist file with message '%@'.", [err localizedDescription]);
}
}
請更新您的問題與相關的代碼更改文件的路徑。 – rmaddy 2014-11-06 04:46:28
您需要提供更多詳細信息。顯示創建兩條路徑的代碼。 – rmaddy 2014-11-06 04:57:58
在iOS 8中,應用程序容器的文件系統佈局已更改。應用程序及其內容不再存儲在一個根目錄中。 – 2014-11-06 05:07:38