MFMailComposeViewController:如何在电子邮件正文中嵌入可点击的URL链接
我希望我的应用程序使用MFMailComposeViewController
发送电子邮件,以便收件人可以单击嵌入的url
以打开相应的网站。 MFMailComposeViewController
似乎没有明确支持这一点。有任何想法吗?MFMailComposeViewController:如何在电子邮件正文中嵌入可点击的URL链接
:)是的,你可以这样做:
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:subject];
[composer setMessageBody:message isHTML:YES];
其中,消息是只是HTML内容的一个NSString。在里面你可以添加你想要的所有HTML。
使用setMessageBody:isHTML:
并传递正文中的正确HTML链接(<a href="your_url">your link text</a>
),并将YES
传递给isHTML
参数。
你试过对你的代码的建议吗?我在进入这个网站之前试过了,很抱歉地说,它根本不起作用。链接看起来真的是蓝色的,HTML被读为html,但没有链接是可能的。当我点击链接,我可以编辑它......
有什么更好的建议吗?
我删除了我以前的答案,因为它是不正确的和不相关的。经过多次拉动我终于找出了我的情况是怎么回事,可能是在这个问题上发生了什么。
当您为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"];
干杯!
优秀!高兴地了解换行!,节省了我一些时间男士的欢呼 – MaKo 2011-09-25 11:50:33
我有同样的问题。
我的链接是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的屏幕截图:
如果我送的,然后我去“已发送”邮箱链接的作品,所以我认为问题是打开链接的事件。
谢谢。
您是否点击了收到的电子邮件或编辑模式? – AsifHabib 2014-06-17 07:38:17