从 10.9 开始可以使用 ** NSSharingService**(支持附件)!
let emailImage = NSImage.init(named: "待分享的图片")!
let emailBody = "邮件正文"
let emailService = NSSharingService.init(named: NSSharingServiceNameComposeEmail)!
emailService.recipients = ["support@myapp.com"]
emailService.subject = "App支持"
if emailService.canPerform(withItems: [emailBody,emailImage]) {
emailService.perform(withItems: [emailBody,emailImage])
} else {
// 无法发送邮件,可能是因为没有配置邮件账户
// 将邮件地址和说明用 alert 显示给用户
}
网友评论