Search code examples
iosuiapplication

ios button mail to with subject


I have a button that is right now opening the mail application and adding a contact through a property I set up. How can I do this to also add a subject line through a property?

- (IBAction)tourButton:(id)sender {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", self.displayEmail]]];

}

Solution

  • You should use MFMailComposeViewController.

    • (void)setSubject:(NSString*)subject

    The text to display in the subject line.

    This method replaces the previous subject text with the new text. You should call this method before you display the mail composition interface only. Do not call it after presenting the interface to the user.

    Availability Available in iOS 3.0 and later.

    source: https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html#//apple_ref/occ/instm/MFMailComposeViewController/setSubject: