简体   繁体   中英

Objective C: Send email with subject and body and switching app

I want to send eMails with subject and body.

This is my code right now and it works as expected. It´s leaving my app and creating a new message in Mail.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:wettbewerb@neunfornkunst.ch"]];

However, I want to create more complex messages including subject and body like this: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:wettbewerb@neunfornkunst.ch?subject=my Subject?body=my Body"]];

Which does´t do anything at all as soon as I add the subject.
Any idea what I´m doing wrong?

You can try this out.

    MFMailComposeViewController *mcvc = [[MFMailComposeViewController alloc] init];
    mcvc.mailComposeDelegate = self;
    NSString *toAddress = //recepient_name_here;
    [mcvc setToRecipients:[NSArray arrayWithObjects:toAddress,nil]];
    [mcvc setSubject:subject];
    [mcvc setMessageBody:emailBody isHTML:NO];
    [mcvc addAttachmentData:ifAny mimeType:@"application/pdf" fileName:fileName];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM