簡體   English   中英

iPad上的MFMailComposeViewController黑屏

[英]MFMailComposeViewController black screen on iPad

我正在使用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)上,郵件正確彈出了,但是當單擊“發送郵件”或“取消”時,視圖被刪除並留下黑屏(屏幕上的所有內容都消失了)

任何建議將不勝感激,謝謝:)

試試這個代碼

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];

}

我在cocos2d-x游戲中使用此代碼通過電子郵件獲取反饋。

Application::getInstance()->openURL("mailto:" + SUPPORT_EMAIL);

您可以添加主題:

Application::getInstance()->openURL("mailto:" + SUPPORT_EMAIL + "?subject=Hello from NX");

該解決方案已在iOS和Android上進行了測試。

彈出電子郵件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM