0

My app creates some back-up files as Packages (in fact as directories with an extension, and an Exported UTI that conforms to com.apple.package).

I would like to be able to read them as NSData, that I can attach to an email in a MFMailComposeViewController. Actually, it doesn't work because dataWithContentsOfURL: returns nil when I try to read the package (I think because it's a directory, not a regular file).

I know my package files are fine because I can access them on my Mac when I download the "app container" from my iPhone.

I generate them using NSFileWrappers, and calling the writeToURL:options:originalContentsURL:error: method. I don't want to use serializedRepresentation because it generates NSData that can be read only by NSFileWrapper (and I would like to be able to open them on my Mac, by clicking on "Show Packages Contents").

Here is the part of code that doesn't work:

NSURL *finalBackupURL = [outputDirectoryURL URLByAppendingPathExtension:@"ext"];
if (![packageWrapper writeToURL:finalBackupURL options:0 originalContentsURL:nil error:error])
    @throw [NSException exceptionWithError:*error];

NSData *data = [NSData dataWithContentsOfURL:finalBackupURL];

(data = nil whereas the file has well been created)

Thank you for your help

Thomas Albert
  • 275
  • 1
  • 10
  • What about zipping that directory ? – Larme Oct 07 '16 at 08:30
  • I would have preferred avoiding this because it's time consuming (the packages may be heavy, like 50MB or more), but if I have no choice... – Thomas Albert Oct 07 '16 at 08:35
  • 50MB by mail may be heavy too, no? Your mail may be rejected by some intermediate servers because of its weight. If not, maybe a simple tar (which if I remember doesn't compress but just link them all). – Larme Oct 07 '16 at 08:39
  • In fact I want to give the choice to the user either to send it by mail, either to save it on iCloud Drive. But it seems to be the same issue when trying to save a package on iCloud Drive. So I definitively have to transform my packages to regular files.. :( – Thomas Albert Oct 07 '16 at 14:46

0 Answers0