我希望我的应用程序使用MFMailComposeViewController
发送电子邮件,以便收件人可以单击嵌入的url
打开对应的网站。
MFMailComposeViewController
似乎不明确支持此功能。 有什么想法吗?
我希望我的应用程序使用MFMailComposeViewController
发送电子邮件,以便收件人可以单击嵌入的url
打开对应的网站。
MFMailComposeViewController
似乎不明确支持此功能。 有什么想法吗?
我删除了之前的答案,因为它是不正确和无关的。经过长时间的纠结,最终我弄清楚了在我的情况下发生了什么,并且很可能也是这个问题中发生的情况。
当你为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"];
祝福!
是的,你可以这样做:
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:subject];
[composer setMessageBody:message isHTML:YES];
message是一个包含HTML内容的NSString。您可以在其中添加任何HTML。
我有同样的问题。
我的链接是HTML,我可以看到“蓝色”,但如果我点击它,Safari移动版不会打开。我被允许编辑文本。
在一个类中,我有这个:
-(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];
}
setMessageBody:isHTML:
方法,在正文中传递一个正确的HTML链接(<a href="你的链接">你的链接文字</a>
),并将isHTML
参数设置为YES
。你试过在你的代码中尝试你的建议了吗?在来到这个网站之前,我已经尝试过了,但抱歉地说,它根本不起作用。链接的颜色确实是蓝色的,HTML 也被解析了,但没有链接可用。当我点击链接时,我只能编辑它......
有更好的建议吗?