2
我用MFMailComposeViewController
發送郵件給他人。當點擊一個按鈕時,撰寫工作表正在打開,我可以輸入地址,主題,郵件正文。但是,點擊發送按鈕後,郵件頁面不會關閉。MFMailComposeViewController not dismiss
代碼:
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"My image"];
UIImage *myImage = [UIImage imageNamed:@"mobiletuts-logo.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"Image"];
NSString *emailBody = @"Hi, my image";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
- (void)mailComposeController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
希望妳的.h文件中添加'MFMailComposeViewControllerDelegate'協議。 – HRM
是的。我補充說。但它不起作用 – user2474320
電話簿看起來很奇怪,bcoz我在代碼中找不到任何其他錯誤。你是否檢查委託方法是否被調用? – HRM