【问题标题】:MFMailComposeViewController : how do I embed a clickable URL link into the email message bodyMFMailComposeViewController:如何将可点击的 URL 链接嵌入到电子邮件正文中
【发布时间】:2010-01-13 16:39:04
【问题描述】:

我希望我的应用程序使用MFMailComposeViewController 发送电子邮件,以便收件人可以单击嵌入的url 以打开相应的网站。 MFMailComposeViewController 似乎没有明确支持这一点。有什么想法吗?

【问题讨论】:

    标签: iphone objective-c cocoa-touch mfmailcomposeviewcontroller


    【解决方案1】:

    我删除了我之前的答案,因为它不正确且不相关。在拉了很多头发之后,我终于弄清楚了我的情况发生了什么,并且可能是这个问题中发生的事情。

    当您为 MFMailComposeViewController 编写 HTML 正文时,您必须在 HTML 中放置换行符。如果任何一行的长度 > 76 个字符,则正文将被解释如下:

    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable
    

    如果您插入换行符,Content-Transfer-Encoding: quoted-printable 将不会发生,一切都会按预期进行。假设您有正确的 HTML。

    例如,构建body如下:

    NSMutableString *body = [NSMutableString string];
    // add HTML before the link here with line breaks (\n)
    [body appendString:@"<h1>Hello User!</h1>\n"];
    [body appendString:@"<a href=\"http://www.mysite.com/path/to/link\">Click Me!</a>\n"];
    [body appendString:@"<div>Thanks much!</div>\n"];
    

    干杯!

    【讨论】:

    • 太棒了!很高兴知道换行符!,节省我一些时间,伙计们欢呼
    【解决方案2】:

    :) 是的,你可以这样做:

    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    composer.mailComposeDelegate = self;
    [composer setSubject:subject];
    [composer setMessageBody:message isHTML:YES];                    
    

    其中 message 只是一个带有 HTML 内容的 NSString。在里面你可以添加所有你想要的 HTML。

    【讨论】:

      【解决方案3】:

      我也有同样的问题。

      我的链接是 HTML,我可以看到“蓝色”,但如果我点击它,则无法打开 safari mobile。允许我编辑文本。

      在课堂上我有这个:

      -(id) init{
          self = [super init];
          if (self) {
                  if ([MFMailComposeViewController canSendMail]) {
                      self.mailComposeDelegate = self;
                      [self setSubject: @"Subject"];
                      [self setMessageBody: @"<h2>Body</h2><a href='http://www.google.com'>link example</a>" isHTML: YES];
                  }
                  else {
                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Mail Accounts" 
                                                                      message:@"You don't have a Mail account configured, please configure to send email."
                                                                     delegate:nil 
                                                            cancelButtonTitle:@"OK" 
                                                            otherButtonTitles: nil];
                      [alert show];
                  }
          }
          return self;
      }
      
      -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
          [controller dismissModalViewControllerAnimated: YES];
      }
      

      在这里您可以看到 iPad 屏幕截图:

      如果我发送,然后我去“发送”邮箱链接有效,所以我认为问题是打开链接的事件。

      谢谢。

      【讨论】:

      • 点击完成了吗?如果是,您是否在链接上重定向,然后请在此处发布@Oceanicsix 谢谢
      • 嗨,那是一年多以前的事了,老实说,我不记得我是如何完成这个问题的了。对不起,祝你好运!
      【解决方案4】:

      使用setMessageBody:isHTML: 并在正文中传递正确的HTML 链接(&lt;a href="your_url"&gt;your link text&lt;/a&gt;) 并将YES 传递给isHTML 参数。

      【讨论】:

        【解决方案5】:

        您是否尝试过您的代码?我在访问这个网站之前尝试过,很抱歉,它根本不起作用。链接实际上以蓝色显示,HTML 被读取为 html,但没有链接是可能的。当我点击链接时,我可以编辑它....

        有更好的建议吗?

        【讨论】:

        • 您是点击收到的邮件还是处于编辑模式?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-15
        • 1970-01-01
        • 2023-03-30
        • 2022-11-25
        • 2016-03-17
        • 2018-03-25
        相关资源
        最近更新 更多