首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MFMailComposeViewController模型不显示

MFMailComposeViewController模型不显示
EN

Stack Overflow用户
提问于 2012-11-29 18:24:06
回答 3查看 7.1K关注 0票数 3

我在我的应用程序中为电子邮件提供了MFMailComposeViewController。但是视图并没有显示出来,只显示了上面的发送和取消按钮。

这是单击"Email to Subscribe“按钮后显示的视图屏幕截图。

我已经检查了所有相关的代码。我添加了"MessageUI“框架,并导入了

代码语言:javascript
复制
MessageUI/MessageUI.h , MessageUI/MFMailComposeViewController.h

我使用了以下代码:

代码语言:javascript
复制
 - (void)viewWillAppear:(BOOL)animated {

     [self.view setFrame:CGRectMake(0, 62, 320, 418)];

     [APPDELEGATE.window addSubview:self.view];

     [self.navigationController.navigationBar setHidden:NO];
     self.navigationItem.title=@"Free Subscription";
     [super viewWillAppear:animated]; }


 -(void)viewWillDisappear:(BOOL)animated {
     [self.view removeFromSuperview];
     [super viewWillDisappear:animated]; }



     -(IBAction)btnEmailPressed {
         MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
         if (Apicker != nil)
         {

         [Apicker setSubject:@"Free Subscription"];

         [Apicker setMessageBody:@" " isHTML:NO];

         NSArray *toRecipients = [NSArray arrayWithObjects:@"info@xyz.com", nil];
         [Apicker setToRecipients:toRecipients];

         Apicker.mailComposeDelegate = self;

         if([MFMailComposeViewController canSendMail])
         {
             [self presentModalViewController:Apicker animated:YES];
         }
         else
         {

         }
         [Apicker release];
     } }


     -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError
     *)error{

     NSString *message;

     switch (result) {
         case MFMailComposeResultCancelled:
             message =@"You have canceled your email.";
             break;
         case MFMailComposeResultFailed:
             message=@"Your email is failed";
             break;
         case MFMailComposeResultSent:
             message=@"Your email was successfully sent.";
             break;
         case MFMailComposeResultSaved:
             message=@" Your email has been saved";
             break;

         default:
             message=@" Your email is not send";
             break;
     }
     UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"" message:message delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

     [alt show];
     [alt release];

     [self dismissModalViewControllerAnimated:YES];
      }

我找不到这个问题的原因。

谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-29 18:47:21

IOS6版

代码语言:javascript
复制
-(void)email{
    MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"xyz@gmail.com", nil]];
        [composer setSubject:@""];

        //    [composer.setSubject.placeholder = [NSLocalizedString(@"This is a placeholder",)];

        [composer setMessageBody:@"" isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentViewController:composer animated:YES completion:nil];
    }
    else {
    }
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    if (error) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@",[error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

试试看

对于iOS 5

代码语言:javascript
复制
-(void)email:(id)sender{
    MFMailComposeViewController *composer=[[MFMailComposeViewController alloc]init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"xyz@gmail.com", nil]];
        [composer setSubject:@""];

        //    [composer.setSubject.placeholder = [NSLocalizedString(@"This is a placeholder",)];

        [composer setMessageBody:@"" isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:composer animated:YES];
    }
    else {
    }
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    if (error) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@",[error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissModalViewControllerAnimated:YES];
    }
    else {
        [self dismissModalViewControllerAnimated:YES];
    }
}
票数 8
EN

Stack Overflow用户

发布于 2012-11-29 18:52:19

试着这样修改你的代码:

代码语言:javascript
复制
-(IBAction)btnEmailPressed 
{ 
    MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
    if (Apicker != nil)   
    {
        [Apicker setSubject:@"Free Subscription"];
        [Apicker setMessageBody:@" " isHTML:NO];
        NSArray *toRecipients = [NSArray arrayWithObjects:@"info@xyz.com", nil];
        [Apicker setToRecipients:toRecipients];
        Apicker.mailComposeDelegate = self;

       if([MFMailComposeViewController canSendMail])
       {
           [self presentModalViewController:Apicker animated:YES];
       }
       else
       {
            NSString *recipients = @"mailto:info@xyz.com?cc=&subject=";
            NSString *body = @"&body=";

                NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
            email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
         }
         [Apicker release];
     } 
}
票数 2
EN

Stack Overflow用户

发布于 2012-11-29 18:27:25

.h文件MFMessageComposeViewControllerDelegateMFMailComposeViewControllerDelegate中添加这两个委托

更新

代码语言:javascript
复制
     if ([MFMailComposeViewController canSendMail]) {
            appDelegate.imgCapture = [self captureView];
            [appDelegate.imgCapture retain];
            MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
            NSString *mailBody = @"Set Your Body Message";


            [mailComposeViewController setMessageBody:mailBody isHTML:NO];
            mailComposeViewController.mailComposeDelegate = self;
            [self presentViewController:mailComposeViewController animated:YES completion:nil];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"e-Mail Sending Alert"
                                                            message:@"You can't send a mail"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13623597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档