-1

I have an iOS app that should allow the user to select a pdf file and send it via there email account, I have the below code that presents the user with the email and shows the pdf attached, however with the email is send the pdf is not attached to the received email.

-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Public Holidays"];


    NSString *plistFilePath = [[NSBundle mainBundle] pathForResource:currentCountry ofType:@"pdf"];

    NSData *myData = [[NSFileManager defaultManager] contentsAtPath:plistFilePath];
    [picker addAttachmentData:myData mimeType:@"application/pdf" fileName:currentCountry];

    // Fill out the email body text
    NSString *emailBody = @"Attached to this email is the PDF bought";
    [picker setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:picker animated:YES];
}
1
  • Is it a plist file or a PDF file? Is the file being found or is it nil?
    – matt
    May 18, 2015 at 9:08

1 Answer 1

0

Code is correct. You should check the filename. Is it a valid string(filename). Also presentModalViewController is deprecated. You should use presentViewController:animated:completion. Check this on device, not on simulator.

3
  • Yes it would see them filename is not valid for some reason, any ideas? May 18, 2015 at 14:56
  • seems that the filename of the file was wrong, it was england_wales.pdf but the code should be "england wales.pdf" i renamed the file in xcode but it still shows wrong in the app May 18, 2015 at 15:13
  • You should delete the app from device or simulator. Remove derived data. then run after Product->Clean
    – Ritu
    May 19, 2015 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.