ThirdPartyMailer
使用自定义URL方案与第三方iOS邮件客户端进行交互。
支持的邮件客户端
客户端 | URL方案 | App Store |
---|---|---|
Sparrow | sparrow |
已停止维护 |
Gmail | googlegmail |
链接 |
Dispatch | x-dispatch |
链接 |
Spark | readdle-spark |
链接 |
Airmail | airmail |
链接 |
Microsoft Outlook | ms-outlook |
链接 |
Yahoo Mail | ymail |
链接 |
Fastmail | fastmail |
链接 |
ProtonMail | protonmail |
链接 |
遗憾的是,并非所有邮件客户端都提供由ThirdPartyMailer支持的URL方案。如果您知道其他备选方案,请告诉我们。
如何安装
Swift 包管理器
在 Xcode 中,点击“文件”菜单,选择“Swift 包”,然后点击“添加包依赖…”,输入此仓库的 URL:https://github.com/vtourraine/ThirdPartyMailer.git
。
CocoaPods
使用 CocoaPods,只需将 ThirdPartyMailer 添加到你的 Podfile 中。
pod 'ThirdPartyMailer'
或者,你可以手动从 Sources 文件夹导入文件。
使用方法
获取支持客户端列表
let clients = ThirdPartyMailClient.clients
测试客户端可用性(即 app 是否已安装)
Info.plist
文件中声明相关 URL 方案,通过添加 LSApplicationQueriesSchemes
数组来实现。您可以在这里找到示例,或者查看文档。
if ThirdPartyMailer.isMailClientAvailable(client) {
// ...
}
打开客户端(可选消息收件人、主题、正文、抄送和密送)
ThirdPartyMailer.openCompose(client, recipient: "[email protected]")
ThirdPartyMailer.openCompose(client, recipient: "[email protected]", subject: "Hello", body: "Good morning…", cc: "[email protected]", bcc: "[email protected]")
🆕 使用系统默认电子邮件客户端
如果您未指定客户端,openCompose(…)
函数将使用.systemDefault
,为标准mailto:
方案定义的客户端。默认情况下,它将打开Apple Mail,但如果用户已选择自定义电子邮件客户端(iOS 14),则它将自动打开。
ThirdPartyMailer.openCompose(recipient: "[email protected]")
要求
ThirdPartyMailer采用Swift 5.0编写,需要iOS 10.0及以上版本,Xcode 10.2及以上版本。
致谢
ThirdPartyMailer由Vincent Tourraine创建。
许可证
ThirdPartyMailer遵循MIT许可证。有关更多信息,请参阅LICENSE.txt文件。