【问题标题】:ios button mail to with subject [duplicate]带有主题的ios按钮邮件[重复]
【发布时间】:2014-04-25 17:07:51
【问题描述】:

我有一个按钮,现在正在打开邮件应用程序并通过我设置的属性添加联系人。如何通过属性添加主题行?

- (IBAction)tourButton:(id)sender {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", self.displayEmail]]];

}

【问题讨论】:

  • 你考虑过MFMailComposeViewController吗?
  • 该副本并非特定于 iOS,但一般答案适用。顺便说一句 - 第二个答案比第一个好。

标签: ios uiapplication


【解决方案1】:

试试这个:

- (IBAction)tourButton:(id)sender {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@?subject=%@", self.displayEmail, @"mail_subject_here"]]];

}

您还可以添加其他参数:
抄送:&cc=cc_mail@example.com
正文:&body=mail_body

适用于 iOS 11.0 及更高版本。 Swift 4.2 +

let emailStr = "\(EMAIL_TO)?subject=\(Email_Subject)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let url = URL(string: "mailto:\(emailStr ?? "")") {
       UIApplication.shared.open(url)
}

【讨论】:

    【解决方案2】:

    你应该使用 MFMailComposeViewController。

    • (void)setSubject:(NSString*)subject

    要在主题行中显示的文本。

    此方法用新文本替换之前的主题文本。您应该在仅显示邮件撰写界面之前调用此方法。将界面呈现给用户后不要调用它。

    可用性 适用于 iOS 3.0 及更高版本。

    来源: https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html#//apple_ref/occ/instm/MFMailComposeViewController/setSubject:

    【讨论】:

    • 谢谢。我刚刚使用 MFMailComposeViewController 来设置所有内容。此外,它还可以从应用内打开电子邮件。
    • @Packy 很高兴我能帮上忙 :)
    猜你喜欢
    • 2015-10-27
    • 2018-11-10
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多