我有一個應用程序,我使用電子郵件發展商按鈕。當我按下按鈕VEMailView-控制器打開。 這只是MFMailComposeViewController的包裝。MFMailComposeViewController不關閉
當我按下「發送」按鈕,控制器必須關閉,但我看到只是白色的窗口。不再。它必須關閉到主ViewController。怎麼修?
這是我的代碼:
#import <MessageUI/MessageUI.h>
#import "VEMailView.h"
@interface VEMailView() <
MFMailComposeViewControllerDelegate,
UINavigationControllerDelegate
>
// UILabel for displaying the result of the sending the message.
@end
@implementation VEMailView{
BOOL alreadyOpened;
}
- (void)viewDidLoad
{
[super viewDidLoad];
alreadyOpened = NO;
}
- (void) viewDidAppear:(BOOL)animated {
[self showMailPicker];
}
- (void)showMailPicker
{
if ([MFMailComposeViewController canSendMail])
{
[self displayMailComposerSheet];
}
}
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"iOS"];
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
NSString *emailBody = @" ";
[picker setMessageBody:emailBody isHTML:NO];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: Mail sending canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: Mail sending failed");
break;
default:
NSLog(@"Result: Mail not sent");
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
'[self dismissViewControllerAnimated:YES completion:nil];'=>'[controller dismissViewControllerAnimated:YES completion:nil];' – Larme
@Larme,no。它不起作用。 – Vyacheslav
我在這裏看不到任何問題。你能發送你的示例代碼嗎?我試過你的代碼,但我什麼都看不到 – VietHung