【问题标题】:How to send email using UIBarButtonItem [duplicate]如何使用 UIBarButtonItem 发送电子邮件 [重复]
【发布时间】:2011-11-22 10:07:24
【问题描述】:

可能重复:
how to send email using UIbarbuttonitem without using MFMailComposerViewController

如图所示,该应用程序用于在单击发送按钮时发送邮件。

我发现它没有显示 MFMailComposerViewController。

这怎么可能?如何获得此功能?

【问题讨论】:

  • 您能否编辑您的问题以显示单击“发送”栏按钮时触发的代码/操作方法?
  • 这张图片是演示应用程序,我想在我的应用程序中实现这种功能。所以我没有任何代码和知识。
  • 如果您想提供更多上下文或详细信息,请编辑您的原始问题。
  • 我每次都需要提交 MFMailComposerViewController 吗?我不想介绍它。我该怎么做?

标签: iphone objective-c ios4 mfmailcomposeviewcontroller


【解决方案1】:

听起来你只需要仔细阅读教程。

我是通过 Google 找到的:

New In iPhone 3.0 Tutorial Series, Part 2: In App Email, MessageUI

是的,上面写着“iPhone 3.0”,但相同的概念和代码在 iOS 5 中应该可以正常工作。

【讨论】:

    【解决方案2】:
    - (void)MailButton:(id)sender
    {
        if ([MFMailComposeViewController canSendMail]) {
            //atableView.scrollEnabled=YES;
            //[socailNetworkView removeFromSuperview];
        //  self.navigationItem.title = @"Contents";
            MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
            mailViewController.mailComposeDelegate = self;
            [mailViewController setSubject:@""];
            [mailViewController setMessageBody:@"" isHTML:NO];
            NSString *string = [NSString stringWithFormat:@"", nil];
    
    
            NSArray *mailArr = [[NSArray alloc] initWithObjects:string,nil];
            [mailViewController setToRecipients:mailArr];
            [self presentModalViewController:mailViewController animated:YES];
            [mailViewController release];
    
        }
    
        else {
    
            NSLog(@"Device is unable to send email in its current state");
    
        }
    }
    
    
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;
    
    {
    
        NSLog(@"Mail");
        NSString  *str=@"";
        switch (result) {  
            case MFMailComposeResultCancelled:  
                NSLog(@"Mail send canceled.");  
                str=@"\nMail sending cancelled";
                //msgLabel.text=str;
                //          [msgLabel setFont:[UIFont fontWithName:@"Arial" size:18]];
                //          msgLabel.textColor=[UIColor colorWithRed:(54.0/255.0) green:(2.0/255) blue:(1.0/255) alpha:1.0];
    
                /* 
                 Execute your code for canceled event here ... 
                 */  
                break;  
            case MFMailComposeResultSaved:  
                NSLog(@"Mail saved."); 
                str=@"Mail saved";
                /* 
                 Execute your code for email saved event here ... 
                 */  
                break;  
            case MFMailComposeResultSent:  
                NSLog(@"Mail sent.");  
                str=@"Mail sent";
                /* 
                 Execute your code for email sent event here ... 
                 */  
                break;  
            case MFMailComposeResultFailed:  
                str=@"Mail not sent";
                NSLog(@"Mail send error: %@.", [error localizedDescription]);  
                /* 
                 Execute your code for email send failed event here ... 
                 */  
                break;  
            default:  
                break;  
        }
        //alertLabel.text=str;
        //  [viewAlert setBackgroundColor:[UIColor clearColor]];
        //  [self.view addSubview:viewAlert];
    
        [self dismissModalViewControllerAnimated:YES];
    }
    

    【讨论】:

    • 不错的答案,Saranya(我正在 +1 上)。不过,您应该清理格式。
    • 谢谢你,我肯定会更新......我只是突然发送了答案,没有格式化;)
    • 它会打开默认的 MFMailComposerView 吗?
    • 是...将邮件按钮功能添加到您的按钮单击中。它将打开默认的 MFMailComposerView。
    猜你喜欢
    • 2013-05-26
    • 2020-04-24
    • 2012-03-22
    • 2015-12-10
    • 2015-09-30
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多