使用 Unity 在 iOS 应用程序上发送电子邮件时出错

Error while sending email on iOS app with unity

本文关键字:电子邮件 出错 程序上 应用程序 Unity iOS 应用 使用      更新时间:2023-10-16

我正在做一个学校项目,我正在尝试记录从我在 Unity 中制作的游戏中存储的数据。

我的问题是我想通过电子邮件将数据真实地发送到应用程序。 一切正常,电子邮件与数据一起发送等。但是当我将应用程序构建到 iOS 设备时,它不会发送电子邮件。

我在 Unity 中没有任何错误,但是当我构建应用程序时,我在 Xcode 中收到此错误。请参阅下面的错误。我希望有人能帮助我。

问候

格奥尔基·伊利耶夫

MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.Net.Configuration.MailSettingsSectionGroup'.
  at Mono.Security.Authenticode.AuthenticodeBase.GetSecurityEntry () [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSectionGroupInstance (System.Configuration.SectionGroupInfo group) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationSectionGroupCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in <filename unknown>:0 
  at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
  at System.Net.Mail.SmtpClient..ctor (System.String host, Int32 port) [0x00000] in <filename unknown>:0 
  at MonoGmail.Start () [0x00000] in <filename unknown>:0 
(Filename: currently not available on il2cpp Line: -1)

添加了@programmers解决方案并得到了一个新的混合错误。

MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.Net.Configuration.MailSettingsSectionGroup'.
  at StartMenu.CloseApp () [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigInfo.CreateInstance () [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Comparer`1[T].get_Default () [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSectionGroupInstance (System.Configuration.SectionGroupInfo group) [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationSectionGroupCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0 
  at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in <filename unknown>:0 
  at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in <filename unknown>:0 
  at System.MonoTODOAttribute..ctor () [0x00000] in <filename unknown>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0 
  at System.Net.Mail.SmtpClient..ctor (System.String host, Int32 port) [0x00000] in <filename unknown>:0 
  at System.Net.Mail.SmtpClient..ctor (System.String host) [0x00000] in <filename unknown>:0 
  at Mono_Gmail.Start () [0x00000] in <filename unknown>:0 
  at System.Array.GetGenericValueImpl[T] (Int32 pos, .T& value) [0x00000] in <filename unknown>:0 
  at System.Array.GetGenericValueImpl[T] (Int32 pos, .T& value) [0x00000] in <filename unknown>:0 
  at System.Array.GetGenericValueImpl[T] (Int32 pos, .T& value) [0x00000] in <filename unknown>:0 
  at System.Array.GetGenericValueImpl[T] (Int32 pos, .T& value) [0x00000] in <filename unknown>:0 
System.Array:GetGenericValueImpl(Int32, T&)
System.Array:GetGenericValueImpl(Int32, T&)
System.Array:GetGenericValueImpl(Int32, T&)
System.Array:GetGenericValueImpl(Int32, T&)
(Filename: currently not available on il2cpp Line: -1)

这是 IL2CPP 中的一个错误。 Unity 没有任何计划在短期内解决此问题,因为有一个临时解决方案可以修复它。

在您的链接.xml中,向其添加以下内容。

<linker>
<assembly fullname="System">
<type fullname="System.Net.Configuration.MailSettingsSectionGroup" preserve="all"/>
<type fullname="System.Net.Configuration.SmtpSection" preserve="all"/>
<type fullname="System.Net.Configuration.SmtpNetworkElement" preserve="all"/>
</assembly>
</linker>

它基本上是告诉Xcode不要剥离这些邮件内容。

如果您没有 link.xml,请创建它并将上面的代码放入其中,然后将文件放在 Asset 文件夹中。重新生成项目。

编辑

根据下面的评论,现在还需要添加以下行:

<type fullname="System.Net.Configuration.SmtpSpecifiedPickupDirectoryElement" preserve="all"/>