14

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

4

5 回答 5

27

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

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

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

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

例如,按如下方式构建主体:

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"];

干杯!

于 2010-11-11T20:03:00.053 回答
18

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

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

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

于 2010-01-13T16:52:23.680 回答
9

我也有同样的问题。

我的链接是 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 屏幕截图: iPad 屏幕截图

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

谢谢。

于 2012-06-06T11:47:45.173 回答
6

setMessageBody:isHTML:在正文 ( <a href="your_url">your link text</a>)中使用并传递适当的 HTML 链接并传递YESisHTML参数。

于 2010-01-13T16:51:44.523 回答
5

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

有更好的建议吗?

于 2010-11-04T14:44:47.397 回答