2014-11-06 58 views
2

我試圖從應用程序包複製一個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]); 
    } 
} 
+0

請更新您的問題與相關的代碼更改文件的路徑。 – rmaddy 2014-11-06 04:46:28

+0

您需要提供更多詳細信息。顯示創建兩條路徑的代碼。 – rmaddy 2014-11-06 04:57:58

+0

在iOS 8中,應用程序容器的文件系統佈局已更改。應用程序及其內容不再存儲在一個根目錄中。 – 2014-11-06 05:07:38

回答

0

在iOS 8中,應用程序容器的文件系統佈局已更改。應用程序及其內容不再存儲在一個根目錄中。

-(NSString *)documentPath 
{ 
    NSString *str=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    str = [str stringByAppendingFormat:@"/configUrl.plist"]; 

    return str; 
} 
+0

這是否意味着每個iOS版本都必須徹底測試該應用程序。是否iOS應用程序不提供前向兼容性? – 2014-11-06 05:37:12

+0

感謝上面的代碼工作:) – 2014-11-06 06:40:42

+0

不需要beacuase上面的路徑重定向爲應用程序存儲。如果這對你有幫助,那麼請接受答案謝謝 – 2014-11-06 07:09:19