0

I've got an archive I'm trying copy the contents of into the Documents directory. It works fine in the simulator but aborts with an error on a device.

- (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;    

}

I get the following output in the console:

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.)
Chait
  • 1,052
  • 2
  • 18
  • 30

1 Answers1

0

I think you are only allowed to write to the Documents directory on the phone, thus add "Documents" to your dirurl just before your (A Document Being ...)

Per Arve
  • 226
  • 2
  • 7