每次要用到都會忘記,隨手記一下好了方便 Copy/Paste
有許多是本公司自有的 Object,大家可以忽略掉,改成自已的Code
1.
MessageUI.framework
2.
#import <MessageUI/MessageUI.h>
3.
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObjects:@"xcoder.tw@gmail.com", nil]];
[controller setSubject:@"信件主指"];
[controller setMessageBody:[NSString stringWithFormat:@"請填寫以下項目\nApp版本:%@ \n裝置型號: \n系統版本: \n電信商:",[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]] isHTML:NO];
[self presentViewController:controller animated:YES completion:^{
//nil
}];
}
else {
[UIAlertView Dai_alertViewWithTitle:@"無法使用寄信功能。" message:@"請確認您裝置上的信箱是已設定。" cancelButtonTitle:@"確定"];
}
Delegate:
4.
#pragma mark MFMail delegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
switch (result) {
case MFMailComposeResultCancelled:
{
[GlobalFunctions HUDStartWithString:@"取消寄信。" dismissAfterDelay:2.0f];
}
break;
case MFMailComposeResultSaved:
{
[GlobalFunctions HUDStartWithString:@"信件已儲存。" dismissAfterDelay:2.0f];
}
break;
case MFMailComposeResultSent:
{
[GlobalFunctions HUDStartWithString:@"成功送出,感謝您的寶貴意見。" dismissAfterDelay:2.0f];
}
break;
case MFMailComposeResultFailed:
{
[GlobalFunctions HUDStartWithString:@"傳送失敗,請再試一次。" dismissAfterDelay:2.0f];
}
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}