setMessageBody 中忽略新行和返回

发布于 2024-08-27 10:06:48 字数 948 浏览 12 评论 0原文

我是不是在做一些蠢事?我可以预填写并发送电子邮件,但电子邮件正文中的“\r\n”被忽略:

- (void) sendEventInEmail
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    NSString *emailSubject = [eventDictionary objectForKey:EVENT_NAME_KEY];

    [picker setSubject:emailSubject];

    // Fill out the email body text
    NSString *iTunesLink = @"http://itunes.apple.com/gb/app/whats-on-reading/id347859140?mt=8"; // Link to iTune App link
    NSString *content = [eventDictionary objectForKey:@"Description"];
    NSString *emailBody = [NSString stringWithFormat:@"%@\r\nSent using <a href = '%@'>What's On Reading</a> for the iPhone.", content, iTunesLink];

    [picker setMessageBody:emailBody isHTML:YES];

    picker.navigationBar.barStyle = UIBarStyleBlack;

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

问候

戴夫

Am I doing something dumb? I can pre-fill and email ok but the "\r\n" is ignored in the emailBody:

- (void) sendEventInEmail
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    NSString *emailSubject = [eventDictionary objectForKey:EVENT_NAME_KEY];

    [picker setSubject:emailSubject];

    // Fill out the email body text
    NSString *iTunesLink = @"http://itunes.apple.com/gb/app/whats-on-reading/id347859140?mt=8"; // Link to iTune App link
    NSString *content = [eventDictionary objectForKey:@"Description"];
    NSString *emailBody = [NSString stringWithFormat:@"%@\r\nSent using <a href = '%@'>What's On Reading</a> for the iPhone.", content, iTunesLink];

    [picker setMessageBody:emailBody isHTML:YES];

    picker.navigationBar.barStyle = UIBarStyleBlack;

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

Regards

Dave

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

几度春秋 2024-09-03 10:06:48

如果 isHTML 设置 YES \n 不起作用,您必须设置 isHTML:NO 或使用 HTML 换行符,例如
输入 >新行。

<代码>

插入一个新的段落,这通常意味着双换行符。

尝试使用 isHTML:YES:

[picker setMessageBody:@"1st line<br />2nd line<br />3rd line<br />and so on..." isHTML:YES]; 

如果 isHTML:NO 只需输入 \n

[picker setMessageBody:@"1st line\n2nd line\n3rd line\nand so on..." isHTML:NO]; 

它会给你这个:

第一行
第二行
第三行
依此类推...

If isHTML set YES \n does not work you either have to set isHTML:NO or use a HTML line break such as <br /> to enter a new line.

<p> </p> inserts a new paragraph which usually means double line break.

Try this with isHTML:YES:

[picker setMessageBody:@"1st line<br />2nd line<br />3rd line<br />and so on..." isHTML:YES]; 

If isHTML:NO just put \n

[picker setMessageBody:@"1st line\n2nd line\n3rd line\nand so on..." isHTML:NO]; 

It will give you this:

1st line
2nd line
3rd line
and so on...

百变从容 2024-09-03 10:06:48

Doh...一直在努力将 Objective C 字符串与 HTML 混合在一起。使用

标签进行修复。

戴夫

Doh... been working too hard and mixing Objective C strings with HTML. Used <p> and </p> tags to fix.

Dave

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文