1


I started implementing UIDocumentPickerViewController today and I've hit a brick wall. I've gotten it to import documents and give me the NSURL for it, but when I use an iWork document, the NSData that I use is null. Its probably because the iWork documents are directories instead of files, and I took a look at some of the other questions on StackOverflow, and none of them seem to help or offer a solution other than zipping them, which seems wrong considering when they are done using a share sheet in the respective iWork app it works fine.

Here is my code:

    NSArray* components = [[url lastPathComponent] componentsSeparatedByString:@"."];

    NSData* data = [[NSData alloc] initWithContentsOfURL:url];

    NSString* filename = [[[url lastPathComponent] stringByReplacingOccurrencesOfString:[components lastObject] withString:@""] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


    NSString* newPath = [NSString stringWithFormat:@"%@/tmpFiles/%@%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0],filename,[components lastObject]];
    [data writeToFile:newPath atomically:YES];

    [self.files addObject:[NSURL fileURLWithPath:newPath]];
    [self updateFileCount];

Has anyone else figured out how to solve this problem? Thanks.

Lorenzo
  • 3,293
  • 4
  • 29
  • 56
BlueSpud
  • 1,555
  • 3
  • 19
  • 44

1 Answers1

0

Documents of type .pages or .numbers are no single files, but bundles. So you cannot read them with -dataWithContentsOfURL:.

Did you check copying with -copyItemAtURL:toURL:error: (NSFileManager)?

Dan
  • 53
  • 3