forked from Xcode-Snippets/Objective-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfmailcomposeviewcontroller_initialization_&_delegate.m
38 lines (32 loc) · 1.46 KB
/
mfmailcomposeviewcontroller_initialization_&_delegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// MFMailComposeViewController Initialization & Delegate
//
//
// IDECodeSnippetCompletionPrefix: mailcomp
// IDECodeSnippetCompletionScopes: [All]
// IDECodeSnippetIdentifier: 6AF073B8-5718-4822-A520-2EC3E574A9F5
// IDECodeSnippetLanguage: Xcode.SourceCodeLanguage.Objective-C
// IDECodeSnippetUserSnippet: 1
// IDECodeSnippetVersion: 2
#import <MessageUI/MessageUI.h>
- (void)presentModalMailComposerViewController {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] init];
composeViewController.mailComposeDelegate = self;
[composeViewController setSubject:<#Subject#>];
[composeViewController setMessageBody:<#Body#> isHTML:YES];
[composeViewController setToRecipients:@[<#Recipients#>]];
[self presentModalViewController:composeViewController animated:YES];
} else {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"<#Cannot Send Mail Message#>", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil] show];
}
}
#pragma mark - MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
if (error) {
<#Handle error#>
}
[self dismissModalViewControllerAnimated:YES];
}