I would like to know if there is any way to determine when the user presses the “send” button when composing an email with native.showPopup?
This is very important as I want to acknowledge the user that his or her email was indeed received. Otherwise, the user has no way to know if the email in fact was sent correctly, or an error occurred along the way. As a result, the user will have a very negative experience.
I would like to avoid this by displaying a simple “thank you for your feedback” type message after the email is sent.
“applicationResume” does NOT fire when pressing the “send” button (but does when I exit the app and come back later).
Below is the code I’m using. If you would be so kind as to go over the code I’m using and point out anything I’m doing incorrectly I would appreciate it.
Thanks!
local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight -- Require the widget library local widget = require( "widget" ) -- Email -------------------------------------------------------------------------------- local function showEmailNotSupportedAlert() print( "Email not supported/setup on this device" ) native.showAlert( "Alert!", "Email not supported/setup on this device.", { "OK" } ) end -- Show Thank You message here local function onSystemEvent( event ) if (event.type == "applicationResume") then showThankYouMessage() -- Appropriate code goes here Runtime:removeEventListener("system", onSystemEvent) end end -- onRelease listener for 'sendEmail' button local function onSendEmail( event ) if native.canShowPopup( "mail" ) then Runtime:addEventListener( "system", onSystemEvent ) local options = { to = { "jane.doe@example.com" }, cc = { "jane.smith@example.com" }, subject = "General Feedback", body = "This is my feedback.", } local result = native.showPopup("mail", options) if not result then showEmailNotSupportedAlert() end else showEmailNotSupportedAlert() end end -- CREATE BUTTONS ----------------------------------------------------------------------- local sendEmail = widget.newButton { left = 0, top = 0, width = 200, height = 50, label = "Compose Email", onRelease = onSendEmail } -- center horizontally on the screen sendEmail.x = centerX sendEmail.y = \_H - 156
That’s weird since I still can’t get mine to work…
@RG
I copied your code verbatim and still can’t get it to work. In fact, it yielded the exact same result as my original code posted above, i.e. applicationResume( ) does not fire when email is sent (even with native.setKeyboardFocus(nil) called), but fires when I exit the app and come back later.
You copied my code or you built and ran my example?
If not the latter, please try that and tell us if building my example directly works for you or not.
Note: I (almost) never build tests for iOS because it is much more painful to set up that android, which can be done simply by building with the default build certificate.
As far as I can gather from our conversation, looks like it is impossible to tell when the user pressed “Send” on iOS (not the case for Android apparently).
This is a real problem as the timing to show the “thank you” message is unclear.
So I came up with my own “solution” (solution is a euphemism). It is not really a solution at all, so “workaround” might be more appropriate nomenclature.
The key was to not consider when the “Send” button was tapped at all.
One observes on iOS that (Android behavior unknown) the native.showPopup( ) call obscures the entire screen.
I took advantage of this fact by basically calling showThankYouMessage( ) immediately before calling native.showPopup( ).
Since the popup consumes the entire screen, the user doesn’t know that the showThankYouMessage( ) has already been called. And when the user taps “Send” (thereby killing the popup), the thank you message is right there, as if it was called when the user tapped “Send”.
There is about a 1 second delay for the native.showPopup( ) to actually display, so timer.performWithDelay(1000, function( ) showThankYouMessage( ) end) should be used.
One minor issue with this approach is that the same thank you message will be displayed even when the user taps “Cancel”, but I do not see this as a significant problem.
@kc - Copying my code into your project isn’t exactly the same as building my standalone project. If you have even the smallest issue in your project it may be interfering with the code you copied.
This is why I verify problems in standalone examples. If the standalone example works, then there is something in the project interfering/causing the issue.
Also, I don’t know what “and behavior I observed is final” means.
@kc - Copying my code into your project isn’t exactly the same as building my standalone project. If you have even the smallest issue in your project it may be interfering with the code you copied.
Of course, I understand. I should mention that I commented out my entire main.lua and replaced it with yours, so there is no room for interference.
I know its a stretch, but what about something in your build.settings or config.lua file? The likelihood is low.
I come from validation background which is why I’m pushing so hard on this.
I start from known quantity: A basic, stand-alone project that worked for myself and others including @sieler2
Then I would build and run it in your environment, completely unchanged.
At this point,
If it works, I start making small changes (like substituting config.lua from the problem project; next step build.settings, …) i.e. I work up to the point of failure.
If it fails, then I know that: “It works for some builds of a Android (perhaps not all), and if fails for some iOS builds (perhaps not all).”
If I get a chance, I’ll build this for my iPad and see what I get and then post back.
That said, it may not happen if my schedule gets too busy.
You are correct, the app is not getting a resume event. In fact it isn’t suspending the app at all. I think this is an iOS issue as I see this in the log window:
However, you don’t see this and that tells me it is not suspending.
On a side note I hate debuggion iOS apps because the console is way too noisy. (If anyone reading this has tips on reducing that noise please share your techniques.)
Why not simply run the thank you response on a timer after they cause the email popup code to run? You may be thanking folks who cancel too, but at least you get past this and thank those who send emails.
Why not simply run the thank you response on a timer after they cause the email popup code to run? You may be thanking folks who cancel too, but at least you get past this and thank those who send emails.
Yes, that is exactly what I ended up doing. To quote myself from an earlier post:
The key was to not consider when the “Send” button was tapped at all.
One observes on iOS that (Android behavior unknown) the native.showPopup( ) call obscures the entire screen.
I took advantage of this fact by basically calling showThankYouMessage( ) immediately before calling native.showPopup( ).
Since the popup consumes the entire screen, the user doesn’t know that the showThankYouMessage( ) has already been called. And when the user taps “Send” (thereby killing the popup), the thank you message is right there, as if it was called when the user tapped “Send”.
Sometimes, the solution to a problem is to not solve the problem at all