gpt4 book ai didi

ios - iPad 上的 MFMailComposeViewController 黑屏

转载 作者:行者123 更新时间:2023-11-29 03:16:24 27 4
gpt4 key购买 nike

我正在使用 cocos2d-x 框架,我需要在点击按钮时弹出邮件。

代码在 iphone5 (6.0)、ipod touch 5(6.0) 上运行良好:

MailSender.h

@interface MailSender : UIViewController <MFMailComposeViewControllerDelegate>

{

UIViewController *currentModalViewController;
}

-(void)sendMail:(const char *)subject receiver:(const char *)receiver;

@结束

MailSender.mm

#import "MailSender.h"
#import "../cocos2dx/platform/ios/EAGLView.h"

@implementation MailSender

- (void)sendMail:(const char *)subject receiver:(const char *)receiver
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

mailer.mailComposeDelegate = self;

[mailer setSubject:[NSString stringWithUTF8String:subject]];

NSArray *toRecipients = [NSArray arrayWithObject:[NSString stringWithFormat:@"%s", receiver]];
[mailer setToRecipients: toRecipients];

//NSString *emailBody = [NSString stringWithFormat:@"<p>This is a sample posting in iOS. My Score is %s!</p>",score];
NSString *emailBody = @"";

[mailer setMessageBody:emailBody isHTML:YES];

// only for iPad
// mailer.modalPresentationStyle = UIModalPresentationFormSheet;

UIViewController* rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
currentModalViewController = [UIViewController alloc];
[rootViewController.view addSubview:currentModalViewController.view];
[currentModalViewController presentViewController:mailer animated:true completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
const char *message;
switch (result)
{
case MFMailComposeResultCancelled:
message = "Mail cancelled";
break;
case MFMailComposeResultSaved:
message = "Mail saved";
break;
case MFMailComposeResultSent:
message = "Mail send";
break;
case MFMailComposeResultFailed:
message = "Mail failed";
break;
default:
message = "Mail cancelled";
break;
}
NSLog(@"%s",message);

[currentModalViewController dismissViewControllerAnimated:true completion:nil];
[currentModalViewController.view.superview removeFromSuperview];
[currentModalViewController release];
}

@end

但是在我的 ipad mini (6.0) 上,邮件正确弹出,但当单击“发送邮件”或“取消”时, View 被删除并留下黑屏(屏幕上的所有内容都消失了)

任何建议将不胜感激,谢谢:)

最佳答案

试试这段代码

if ([MFMailComposeViewController canSendMail]) {

mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:@[@"yourmail@com"]];
[mailComposer setSubject:@"Subject"];
[mailComposer setMessageBody:@"hello \n" isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];

}
else{

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error"
message:@"can not send mail with this device"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alert show];
}

编译指示标记 MFMailComposeViewControllerDelegate

-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
if (result) {
NSLog(@"Result : %d",result);
}
if (error) {
NSLog(@"Error : %@",error);
}
[self dismissViewControllerAnimated:YES completion:nil];

}

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

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