– (IBAction)emailSupport:(id)sender
{
NSLog(@“Clicked”);
}
@interface ViewController ()<MFMailComposeViewControllerDelegate>
@end
[code lang=”objc”]
#pragma mark 点击发送按钮
– (IBAction)emailSupport:(id)sender
{
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString *model = [[UIDevice currentDevice] model];
//1.从plist中获得版本号
NSString *key=(NSString *)kCFBundleVersionKey;
NSString *version=[NSBundle mainBundle].infoDictionary[key];
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"lveslxl@163.com",nil]];
[mailComposer setSubject:[NSString stringWithFormat: @"意见反馈( V%@ )",version]];
NSString *supportText = [NSString stringWithFormat:@"Device: %@\niOS Version:%@\n\n",model,iOSVersion];
supportText = [supportText stringByAppendingString: @"意见反馈,畅所欲言吧."];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
}
[/code]
[code lang=”objc”]
– (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
[/code]