rud*_*ifa 13 iphone cocoa-touch objective-c mfmailcomposeviewcontroller
我希望我的应用程序使用MFMailComposeViewController
发送电子邮件,以便收件人可以单击嵌入式url
打开相应的网站.
MFMailComposeViewController
似乎没有明确支持这一点.有任何想法吗?
XJo*_*nes 27
我删除了之前的答案,因为它不正确且无关紧要.经过大量的拔毛后,我终于弄清楚我的情况发生了什么,可能就是这个问题中发生了什么.
在为MFMailComposeViewController组合HTML主体时,必须在HTML中添加换行符.如果任何行长> 76个字符,则正文将解释如下:
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Run Code Online (Sandbox Code Playgroud)
如果您放入换行符,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"];
Run Code Online (Sandbox Code Playgroud)
干杯!
Adr*_*ski 16
:)是的,你可以这样做:
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:subject];
[composer setMessageBody:message isHTML:YES];
Run Code Online (Sandbox Code Playgroud)
其中message只是一个带有HTML内容的NSString.在里面你可以添加你想要的所有HTML.
我也有同样的问题.
我的链接是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];
}
Run Code Online (Sandbox Code Playgroud)
在这里你可以看到iPad屏幕截图:
如果我发送,然后我转到"已发送"邮箱链接工作,所以我认为问题是打开链接的事件.
谢谢.
setMessageBody:isHTML:
在正文(<a href="your_url">your link text</a>
)中使用并传递适当的HTML链接,然后传递YES
给isHTML
参数。
小智 5
您是否尝试过您的代码建议?在访问此网站之前,我已经尝试过了,很遗憾地说,它根本不起作用。链接实际上显示为蓝色,HTML读为html,但无法链接。当我点击链接时,我可以对其进行编辑...。
有更好的建议吗?