0

Not sur if this is duplicate question, but I couldn't find any answer. So In my app I creating files by subclasing UIDocument. Files are stored in Documents app folder. Now I'm trying to attach one of created files to email by code below:

NSError *error = nil;
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
mailView.mailComposeDelegate = self;

NSString *_fileUrl = [fileURL path];
NSString *fileName = [[[fileURL path] lastPathComponent] stringByDeletingPathExtension];

NSData *attatchmentData = [NSData dataWithContentsOfFile:_fileUrl options:NSDataReadingUncached error:&error];

[mailView addAttachmentData:attatchmentData mimeType:@"text/doc" fileName:fileName];

[self presentViewController:mailView
                   animated:YES
                 completion:nil];

And there is problem with line:

NSData *attatchmentData = [NSData dataWithContentsOfFile:_fileUrl options:NSDataReadingUncached error:&error];

It attachmentData is nil and error says:

_code = 257 NSError *error: summary string parsing error

In Apple library I found info about error code 257:

NSFileReadNoPermissionError = 257.

So I assume that there is problem with permission. Anyway it is strange - I can create and save files, rename it, update it or even delete. But I don't know why I cannot attach file to email.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
metal_man
  • 580
  • 1
  • 9
  • 22
  • Can you please post the _fileUrl? – Max Jan 06 '14 at 18:28
  • fileURL is composed as follows: [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] and then string by appending path compponent, so path may look like this: /var/mobile/Applications/5120E211-B7A4-48B2-A76A-47992759E791/Documents/Document1.myDoc – metal_man Jan 06 '14 at 21:10

0 Answers0