从 iOS 10.2.1 上使用 Corona 构建的应用发送带附件的邮件

Send mail with attachments from an app built with Corona on iOS 10.2.1

我需要从我在 iOS 10.2.1 设备上使用 Corona SDK 构建的应用程序发送一封包含附件的电子邮件。我曾经构建过一个 Corona 应用程序,它能够发送带附件的电子邮件,而且运行良好。现在,从 iOS 10.2.1 开始,它似乎不起作用,我不知道是因为我写错了代码还是 native.showPopup 与 [= 不兼容22=] 10.2.1。

我使用的是 Corona 版本 2017.3059。

此外,我用 native.canShowPopup( "mail" ) 检查了我的设备(iPhone 6),它表明邮件弹出功能在设备上可用。

下面是我正在使用的代码。

local widget = require( "widget" )

-- Function to handle button event
local function sendMail( event )
   if ( "ended" == event.phase ) then
      if ( native.canShowPopup( "mail" ) ) then
         native.showAlert( "Alert!", "Mail IS available on this device", { "OK" } )
         local options =
         {
            to = { "john.doe@somewhere.com", "jane.doe@somewhere.com" },
            cc = { "john.smith@somewhere.com", "jane.smith@somewhere.com" },
            subject = "My High Score",
            isBodyHtml = true,
            body = "<html><body>I scored over <b>9000</b>!!! Can you do better?</body></html>"
         }
         native.showPopup( "mail", options )
      else
         native.showAlert( "Alert!", "Mail NOT available on this device", { "OK" } )
      end
   end
end

-- Create the widget
local mailButton = widget.newButton(
{
   label = "Mail",
   fontSize = 64,
   onRelease = sendMail, -- this is my function to send mail
   labelColor = { default={ 1, 1, 1 } },
   labelAlign = "center",
   emboss = false,
   shape = "roundedRect",
   width = 200,
   height = 100,
   cornerRadius = 13,
   fillColor = { default={1,0,0}, over={0,1,1} },
   strokeColor = { default={1,1,1}, over={1,1,1} },
   strokeWidth = 4
}
)

mailButton.x = display.contentCenterX
mailButton.y = display.contentCenterY

我能够让它工作。实际上有两个问题:

1) 由于某种原因,我设备上的电子邮件帐户出现问题。

出于某种原因,我不确定为什么,我不得不删除我的电子邮件帐户并恢复它们,这似乎解决了问题。我觉得这是一个非常常见的配置,我在 Apple iOS 邮件应用程序上安装了两个 Gmail 帐户。但是删除它们并恢复它们就成功了

2) 在触发电子邮件之前不能触发警告框

在我的代码正常工作之前,我必须摆脱:

native.showAlert( "Alert!", "Mail IS available on this device", { "OK" } )

所以工作代码是:

local widget = require( "widget" )

-- Function to handle button event
local function sendMail( event )
   if ( "ended" == event.phase ) then
      if ( native.canShowPopup( "mail" ) ) then
         local options =
         {
            to = { "john.doe@somewhere.com", "jane.doe@somewhere.com" },
            cc = { "john.smith@somewhere.com", "jane.smith@somewhere.com" },
            subject = "My High Score",
            isBodyHtml = true,
            body = "<html><body>I scored over <b>9000</b>!!! Can you do better?</body></html>"
         }
         native.showPopup( "mail", options )
      else
         native.showAlert( "Alert!", "Mail NOT available on this device", { "OK" } )
      end
   end
end

-- Create the widget
local mailButton = widget.newButton(
{
   label = "Mail",
   fontSize = 64,
   onRelease = sendMail, -- this is my function to send mail
   labelColor = { default={ 1, 1, 1 } },
   labelAlign = "center",
   emboss = false,
   shape = "roundedRect",
   width = 200,
   height = 100,
   cornerRadius = 13,
   fillColor = { default={1,0,0}, over={0,1,1} },
   strokeColor = { default={1,1,1}, over={1,1,1} },
   strokeWidth = 4
}
)

mailButton.x = display.contentCenterX
mailButton.y = display.contentCenterY