gpt4 book ai didi

ios - MFMailComposeViewController 不关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:23 28 4
gpt4 key购买 nike

我有一个应用程序,我在其中使用电子邮件给开发人员按钮。当我按下按钮时,VEMailView-controller 打开。这只是 MFMailComposeViewController 的包装器。

当我按下“发送”按钮时, Controller 必须关闭,但我只看到白色窗口。不再。它必须对主 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:@"first@example.com"];

[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

最佳答案

那是因为你正在制作一个额外的 View Controller 。在按钮所在的 View Controller 中创建 MFMailComposeViewController。邮件撰写 Controller 本身就是一个 Controller 。出现白屏是因为这是您的 VEMailView 的默认 View 。摆脱它并使用这些方法:

- (void)showMailPicker;
- (void)displayMailComposerSheet;

在带有按钮的 View Controller 中。也让它成为代表。

关于ios - MFMailComposeViewController 不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23007530/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com