【问题标题】:Sending in-app email发送应用内电子邮件
【发布时间】:2013-08-30 18:54:35
【问题描述】:

我需要在不退出应用程序的情况下发送电子邮件,因为主题和正文已由应用程序设置。我已经知道如何发送电子邮件,但我需要将应用程序退出到电子邮件应用程序,然后单击发送返回到我的应用程序。我不能在不退出或至少不需要点击发送按钮的情况下发送电子邮件,难道不能有某种框架自动发送电子邮件吗?

亲切的问候, 赫巴

【问题讨论】:

    标签: iphone


    【解决方案1】:

    代码如下:

    (不要忘记将 messageUI 框架添加到您的项目中!!!)

    首先导入消息框架:

    #import <MessageUI/MessageUI.h>
    

    然后像这样将自己标记为代表

    @interface MYViewController () <MFMailComposeViewControllerDelegate>
    

    然后拉起作曲家:

    - (IBAction)supportPressed:(id)sender
    {
        if ([MFMailComposeViewController canSendMail]) {
            MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
            [composeViewController setMailComposeDelegate:self];
            [composeViewController setToRecipients:@[@"example@email.com"]];
            [composeViewController setSubject:@"example subject"];
            [self presentViewController:composeViewController animated:YES completion:NULL];
        }
    }
    

    然后处理委托回调并关闭作曲家:

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {
        //Add an alert in case of failure
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用 MFMailComposeViewController 发送应用内电子邮件。您可以在其中一个视图控制器中使用此代码(例如,响应按钮按下)。请注意,您需要将 MessageUI 框架添加到您的应用中。

      #import <MessageUI/MessageUI.h>
      

      呈现邮件视图控制器的代码:

      MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
      
      mail.mailComposeDelegate = self;
      
      [mail setToRecipients:[NSArray arrayWithObject:@"email@example.com"]];
      [mail setSubject:@"Set The Subject Here"];    
      
      [self presentModalViewController:mail animated:YES];
      

      请参阅有关如何实现 mailComposeDelegate 的文档 - 您可以在发送电子邮件或用户取消任务时使用它来关闭模式视图控制器。

      【讨论】:

        【解决方案3】:

        寻找MFMailComposeViewController。另请参阅this 帖子

        【讨论】:

          【解决方案4】:

          要在应用内发送电子邮件,您可以使用 MFMailComposeViewController 类。

          像这样:

          if( [MFMailComposeViewController canSendMail] ) {
              MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
              [mailViewController setRecipients:[NSArray arrayWithObject:@"mail@address.com"]];
              [self.navigationController presentModalViewController:mailViewController animated:YES];
              [mailViewController release];
          }
          

          【讨论】:

            【解决方案5】:

            如果您无法硬编码,请使用此短代码:发送邮件

            【讨论】:

              猜你喜欢
              • 2017-10-15
              • 1970-01-01
              • 2011-09-16
              • 2015-11-05
              • 2017-08-07
              • 1970-01-01
              • 2016-04-17
              • 2017-12-07
              • 1970-01-01
              相关资源
              最近更新 更多