与第三方 iOS 邮件客户端交互,使用自定义 URL Schemes。
客户端 | URL Scheme | App Store |
---|---|---|
Gmail | googlegmail |
链接 |
Spark | readdle-spark |
链接 |
Airmail | airmail |
链接 |
Microsoft Outlook | ms-outlook |
链接 |
Yahoo Mail | ymail |
链接 |
Fastmail | fastmail |
链接 |
Proton Mail | protonmail |
链接 |
Sparrow | sparrow |
已停止维护 |
Dispatch | x-dispatch |
已停止维护 |
遗憾的是,并非所有邮件客户端都提供 URL schemes 以供 ThirdPartyMailer
支持。如果您知道其他可支持的客户端,请告知我们。
在 Xcode 中,点击 “File” 菜单, “Swift Packages”, “Add Package Dependency…”,然后输入此仓库的 URL:https://github.com/vtourraine/ThirdPartyMailer.git
。
使用 CocoaPods,只需将 ThirdPartyMailer 添加到您的 Podfile
pod 'ThirdPartyMailer'
或者,您可以手动从 Sources 文件夹导入文件。
let clients = ThirdPartyMailClient.clients
Info.plist
文件中声明相关的 URL scheme,通过添加 LSApplicationQueriesSchemes
数组。您可以在此处找到示例,或查看文档。
if ThirdPartyMailer.isMailClientAvailable(client) {
// ...
}
ThirdPartyMailer.openCompose(client, recipient: "friend@mail.com")
ThirdPartyMailer.openCompose(client, recipient: "friend@mail.com", subject: "Hello", body: "Good morning…", cc: "cc@mail.com", bcc: "bcc@mail.com")
如果您未指定客户端,openCompose(…)
函数将使用 .systemDefault
,这是一个为标准 mailto:
scheme 定义的客户端。默认情况下,它将打开 Apple Mail,但如果用户选择了自定义邮件客户端 (iOS 14),它将自动打开该客户端。
ThirdPartyMailer.openCompose(recipient: "friend@mail.com")
ThirdPartyMailer 使用 Swift 5.0 编写,需要 iOS 10.0 及以上版本,Xcode 10.2 及以上版本。
ThirdPartyMailer 由 Vincent Tourraine 创建。
ThirdPartyMailer 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE.txt 文件。