native.showPopup mail doesn't work in iOS 10.2.1

I have seen other posts about this for other versions of iOS, but I’m experiencing problems with iOS 10.2.1 for:

native.showPopup( "mail", options )

Here’s my code simplified.  Basically, nothing happens when the button is pressed.  Is this a bug or is there something missing here?  Thanks.  

local widget = require( "widget" ) -- Function to handle button events local function goMail( event ) if ( "ended" == event.phase ) then print( "Button was pressed and released" ) -- Email popup with multiple correspondents and attachments 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 ) end end -- Create the widget local mailButton = widget.newButton( { label = "Mail", fontSize = 64, onRelease = goMail, 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

Here are the older posts:

https://forums.coronalabs.com/topic/66536-nativeshowpopup-not-working-with-email-on-iphone-6-running-ios-1011-not-supported-on-this-device/?hl=%2Bmail+%2Bnative.showpopup

https://forums.coronalabs.com/topic/66262-nativeshowpopup-doesnt-work-in-ios1002/?hl=%2Bmail+%2Bnative.showpopup

Hi @jmiertschin,

Does your code even reach the “goMail” function? I think the issue here is that, because you use the “onRelease” check for the button (other options being “onPress” and “onEvent”), you don’t need to check for the “ended” phase. Basically, using “onRelease” for a button assumes that the button has, well, been released… so you don’t need to check for the “ended” phase.

Try commenting out that conditional check and see what happens:

[lua]

– Function to handle button events

local function goMail( event )

   --if ( “ended” == event.phase ) then

      print( “Button was pressed and released” )

      – Email popup with multiple correspondents and attachments

      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 )

   --end

end

[/lua]

Best regards,

Brent

Thanks for jumping in here @BrentSorrentino.  

I was definitely getting inside the goMail function.  I know this because I put a print statement in there to check for that very thing.  

I went ahead and tried your suggestion of getting rid of the event.phase condition and that did not seem to help.  

I also tried two other things since posting this.  I added a conditional statement using native.canShowPopup( “mail” ) and I get back a response of true for that.  Additionally, I have created a build of this app for Android and it does compose an email message on that platform, so this seems to be an iOS-specific problem.  

Before seeing your response I submitted a bug report to Corona.  But let me show you my revised code with out the event.phase condition and with the canShowPopup condition.  As mentioned, this code works on Android but not on iOS. And Brent, any further suggestions you may have would be greatly appreciated.  Thanks for you help thus far.

 

local widget = require( "widget" ) -- Function to handle button event local function goMail( event ) 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 -- Create the widget local mailButton = widget.newButton( { label = "Mail", fontSize = 64, onRelease = goMail, -- 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

Hi @jmiertschin,

I did a little testing on this. Please check that your device has Mail (and accounts) properly set up. On one iPhone with Mail not configured properly, I got a failure (this is expected; obviously you can’t send mail if Mail is not set up). On another iPhone with Mail set up properly, your exact code worked perfectly. Both phones were running 10.2.1.

Brent

@BrentSorrentino - THANK YOU!!!  

I believe the problem was with my Apple iOS Mail app.  I deleted all my accounts (two Gmail accounts) and reinstated them and the native.showPopup works fine now.  However, this is a bit concerning because whatever it was within the Mail app configuration that was causing conflicts in the first place was not apparent.  When my app users try to use this email function, they may run into the same problems as me and think the app is broken.  I’m not sure that this is a Corona issue, but it would be interesting to hear if other people run into similar situations with their mail app being configured in an incompatible way.  

I would also like to make a note for future readers of this post:

Triggering an alert box (as I have in the code above), did seem to disable the email popup from functioning correctly.  But I previously had unsuccessfully tried triggering an email without the alert box, so I know that it wasn’t my initial problem.

Below is the final correct working code:

local widget = require( "widget" ) local function goMail( event ) 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!", "Emailing from this app not available on this device", { "OK" } ) end end -- Create the widget local mailButton = widget.newButton( { label = "Mail", fontSize = 64, onRelease = goMail, -- 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

 Thanks Brent

Hi @jmiertschin,

Does your code even reach the “goMail” function? I think the issue here is that, because you use the “onRelease” check for the button (other options being “onPress” and “onEvent”), you don’t need to check for the “ended” phase. Basically, using “onRelease” for a button assumes that the button has, well, been released… so you don’t need to check for the “ended” phase.

Try commenting out that conditional check and see what happens:

[lua]

– Function to handle button events

local function goMail( event )

   --if ( “ended” == event.phase ) then

      print( “Button was pressed and released” )

      – Email popup with multiple correspondents and attachments

      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 )

   --end

end

[/lua]

Best regards,

Brent

Thanks for jumping in here @BrentSorrentino.  

I was definitely getting inside the goMail function.  I know this because I put a print statement in there to check for that very thing.  

I went ahead and tried your suggestion of getting rid of the event.phase condition and that did not seem to help.  

I also tried two other things since posting this.  I added a conditional statement using native.canShowPopup( “mail” ) and I get back a response of true for that.  Additionally, I have created a build of this app for Android and it does compose an email message on that platform, so this seems to be an iOS-specific problem.  

Before seeing your response I submitted a bug report to Corona.  But let me show you my revised code with out the event.phase condition and with the canShowPopup condition.  As mentioned, this code works on Android but not on iOS. And Brent, any further suggestions you may have would be greatly appreciated.  Thanks for you help thus far.

 

local widget = require( "widget" ) -- Function to handle button event local function goMail( event ) 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 -- Create the widget local mailButton = widget.newButton( { label = "Mail", fontSize = 64, onRelease = goMail, -- 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

Hi @jmiertschin,

I did a little testing on this. Please check that your device has Mail (and accounts) properly set up. On one iPhone with Mail not configured properly, I got a failure (this is expected; obviously you can’t send mail if Mail is not set up). On another iPhone with Mail set up properly, your exact code worked perfectly. Both phones were running 10.2.1.

Brent

@BrentSorrentino - THANK YOU!!!  

I believe the problem was with my Apple iOS Mail app.  I deleted all my accounts (two Gmail accounts) and reinstated them and the native.showPopup works fine now.  However, this is a bit concerning because whatever it was within the Mail app configuration that was causing conflicts in the first place was not apparent.  When my app users try to use this email function, they may run into the same problems as me and think the app is broken.  I’m not sure that this is a Corona issue, but it would be interesting to hear if other people run into similar situations with their mail app being configured in an incompatible way.  

I would also like to make a note for future readers of this post:

Triggering an alert box (as I have in the code above), did seem to disable the email popup from functioning correctly.  But I previously had unsuccessfully tried triggering an email without the alert box, so I know that it wasn’t my initial problem.

Below is the final correct working code:

local widget = require( "widget" ) local function goMail( event ) 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!", "Emailing from this app not available on this device", { "OK" } ) end end -- Create the widget local mailButton = widget.newButton( { label = "Mail", fontSize = 64, onRelease = goMail, -- 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

 Thanks Brent