您确定要在 mailTo: 链接文本中添加链接属性吗?
您可能想在设置邮件内容属性文本时尝试一下。
let attrText = NSMutableAttributedString.init(string: "Email me")
let mailLink = "mailTo:test@example.com"
let url = NSURL.init(string: mailLink) as NSURL?
attrText.addAttribute(NSAttributedStringKey.link, value: url ?? "", range: NSMakeRange(0, attrText.length))
let documentAttributes = [NSAttributedString.DocumentAttributeKey.documentType : NSAttributedString.DocumentType.html]
do {
let htmlData = try! attrText.data(from: NSMakeRange(0, attrText.length), documentAttributes:documentAttributes)
if let htmlString = String(data:htmlData, encoding:String.Encoding.utf8) {
let messageVC = MFMailComposeViewController()
messageVC.setMessageBody(htmlString, isHTML: true)
}
}