在NSWorkspace.shared.open()
中的其他Stack Overflow code examples之后,我想到了这一点:
@IBAction func mailFileVacuum(_ sender: NSButton) {
let receiver = sender.alternateTitle
let sendAddress = String(format: "mailto:%@@filevacuum.com?subject=FileVacuum %@", receiver, receiver).addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
NSLog("receiver %@", receiver)
let mailUrl = URL(string: sendAddress)
NSLog("mailUrl %@", mailUrl!.absoluteString)
if NSWorkspace.shared.open(mailUrl!) {
print("Default browser was successfully opened to send email. ??")
}
}
☝️让我们得到这个?
我尝试更改默认浏览器,这不是问题。
NSLog(mailUrl)
记录此mailto%3AFeedback%40filevacuum.com%3Fsubject=FileVacuum%20Feedback
看起来不错maybe ...
¿Que Paso?
答案 0 :(得分:2)
您不应对整个 URL进行百分比编码;而是它的各个组成部分。参见Apple URL Scheme Reference。
格式正确的网址应如下所示(即应输出NSLog(mailUrl)
)
mailto:Feedback@filevacuum.com?subject=FileVacuum%20Feedback