2014-02-08 84 views
0

我使用的是cocos2d-x框架,当点击按钮时需要弹出邮件。iPad上的MFMailComposeViewController黑色屏幕

代码工作精细的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; 

@end

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)上邮件弹出正确,但点击“发送邮件”或“取消”视图时除去,留下一个黑色的屏幕(一切都在屏幕上消失了)

任何建议将赞赏,感谢:)

回答

1

试试这个代码

if ([MFMailComposeViewController canSendMail]) { 

       mailComposer = [[MFMailComposeViewController alloc]init]; 
       mailComposer.mailComposeDelegate = self; 
       [mailComposer setToRecipients:@[@"[email protected]"]]; 
       [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]; 

} 
0

我在我的cocos2d-x游戏中通过电子邮件使用此代码进行反馈。

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

您可以添加主题:

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

该解决方案在iOS和Android进行测试。

popup email