0
我有一個檔案我試圖將內容複製到文檔目錄中。它在模擬器中工作正常,但在設備上出現錯誤。NSFileWrapper錯誤寫入URL
- (BOOL)importData:(NSData *)zippedData {
// Read data into a dir Wrapper
NSData *unzippedData = [zippedData gzipInflate];
NSFileWrapper *dirWrapper = [[[NSFileWrapper alloc] initWithSerializedRepresentation:unzippedData] autorelease];
if (dirWrapper == nil) {
NSLog(@"Error creating dir wrapper from unzipped data");
return FALSE;
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *dirUrl = [NSURL fileURLWithPath:documentsDirectory];
NSError *error;
BOOL success = [dirWrapper writeToURL:dirUrl options:NSFileWrapperWritingAtomic originalContentsURL:nil error:&error];
if (!success) {
NSLog(@"Error importing file: %@", error.localizedDescription);
return FALSE;
}
// Success!
return TRUE;
}
我得到了在控制檯下面的輸出:
2013-01-19 22:40:23.865 My App[569:907] Foundation called mkdir("/var/mobile/Applications/1BF53E96-6261-4DEC-8700-60307D84587F/(A Document Being Saved By My App)"), it didn't return 0, and errno was set to 1. 2013-01-19 22:40:23.922 My App[569:907] Error importing file: The operation couldn’t be completed. (Cocoa error 513.)