在 iOS 应用中预填充包含支持信息的邮件
SupportEmail 旨在简化应用支持。通过在您嵌入的支持邮件链接中预填充设备信息,您可以节省时间和用户之间不必要的来回沟通。请查看 Countdowns 或 Recurrence 以了解 SupportEmail 的实际应用效果。
首选的安装方法是使用 Swift Package Manager。从 Xcode 11 开始,您可以直接从 IDE 添加软件包。
您也可以使用 CocoaPods 进行安装。为此,请将以下内容添加到您的 Podfile
pod 'SupportEmail', '~> 4.0'
您也可以使用 Carthage 进行安装。为此,请将以下内容添加到您的 Cartfile
github "schayes04/SupportEmail"
由于 MFMailComposeViewController 的工作方式,您必须在发送邮件的位置之外保留对 SupportEmail 的引用。
var supportEmail: SupportEmail?
使用 SupportEmail 非常简单,只有一个方法。 send
允许您创建邮件并处理最终结果
supportEmail = SupportEmail()
supportEmail.send(to: ["support@test.com"], subject: "Support", from: self) { result, error in
switch result {
case .cancelled:
print("Message cancelled")
case .failed:
print("Message failed")
case .saved:
print("Message saved")
case .sent:
print("Message sent")
}
}
send 函数接受 3 个参数
SupportEmail 还支持提供自定义参数。
supportEmail.customFields = ["Pro Upgrade": "Yes"]
SupportEmail 允许您选择发送文本文件或仅发送电子邮件正文中的内容。默认设置为发送文本文件。如果您发送的是文本文件,您还可以指定文件名。
supportEmail.sendAsTextFile = true
supportEmail.fileName = "Sample File Name"
SupportEmail 允许您提供 tintColor 以自定义导航栏的外观。
supportEmail.tintColor = .blue
SupportEmail 允许您提供 baseLocale 以本地化电子邮件中的系统区域设置。默认为 en-US。
supportEmail.baseLocale = Locale(identifier: "es-US")
SupportEmail 允许您提供 bodyPrefix,它会向电子邮件添加默认正文
supportEmail.bodyPrefix = "Please add any relevant feedback:\n"
SupportEmail 允许您更改 modalPresentationStyle。默认为 .fullScreen。
supportEmail.modalPresentationStyle = .formSheet
此代码根据 MIT 许可证 的条款和条件分发。