如何使用 MFMailComposeViewController 自动将设备信息附加到新电子邮件

How to automatically attach device information to new email with MFMailComposeViewController

如果您使用 TestFlight 发送 Beta 反馈,它会自动附加一个名为 device_information.txt 的文件,其中包含有关设备的一些基本信息。

我想在我的应用程序中创建一个支持按钮,我正在使用 MFMailComposeViewController 创建一个新电子邮件。我如何检索(或创建)device_information.txt 文件,然后将其附加到新电子邮件?

这是 device_information.txt 文件将包含的内容的示例:

App Information:
App Name: [App Name Here]
App Version: 1.0
Installed App Version: 1.0

Device Information:
Device: iPhone6,2
iOS Version: 12.1.2
Language: en-AU (English)
Carrier: [Carrier Here]
Timezone: [Timezone Here]
Architecture: N/A
Connection Status: Cellular data
Paired Apple Watch: N/A

TestFlight 是如何做到这一点的?这一定是可能的,所以如果有人能指导我正确的方向,我将不胜感激。

您可以在 UIDevice 中找到大部分信息 class https://developer.apple.com/documentation/uikit/uidevice

您可以像这样将所需信息附加到邮件文本中:

   MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
   controller.mailComposeDelegate = self;
   [controller setMessageBody:"your message here" isHTML:NO];

或像这样使用附件:

    [controller addAttachmentData:data mimeType:@"text/plain" fileName:@"test.txt"];

在Swift中:

let controller = MFMailComposeViewController()
controller.mailComposeDelegate = self
controller.setMessageBody("My message", isHTML:false)
controller.addAttachmentData(data as Data, mimeType: "text/plain", fileName: "test.txt")