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.