Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 UIActivityViewController Email Attachments

I have reviewed a bunch of posts here, numerous online tutorials/sample code and I'm stumped. In my app I have no problem displaying the UIActivityController natively provided by iOS7 with the sharing options appropriate to my app (AirDrop and mail).

The specific problem I'm having is getting my saved document attached to the email message when the user selects the option to share via mail. The message body is being set to the text, but the attachment is MIA. The relevant code is:

// Generate the XML file to be shared for the currently displayed record... NSURL *url = [self createShareFile];

UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[@"Data shared from my app.", url] applicationActivities:nil];

// Filter out the sharing methods we're not interested in....
controller.excludedActivityTypes = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
                                UIActivityTypePostToWeibo,
                                UIActivityTypeMessage,
                                UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
                                UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
                                UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];

// Now display the sharing view controller.
[self presentViewController:controller animated:YES completion:nil];

What am I missing? My file is being properly created, the contents is correct and the NSURL object contains the proper path to the file.

Thanks!

like image 479
drumz Avatar asked Feb 18 '14 23:02

drumz


1 Answers

Problem solved.....

The code posted in my original post is 100% accurate. The issue ended up being in the way I was constructing the NSURL being returned in my createShareFile method:

Incorrect (original way):

return [NSURL URLWithString:[docFile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

Correct way:

return [NSURL fileURLWithPath:docFile];

As soon as I fixed that, it started working, even with my custom file type.

like image 134
drumz Avatar answered Nov 14 '22 14:11

drumz