Any Event Thrown When User Presses "Send" in native.showPopup("mail") ?

no event is generated for send.  The best you can do is:

  1. Track the fact that you’re about to launch email popup.
  2. Start listening for resume event.
  3. Launch it email popup.
  4. Allow user to do whatever
  5. Detect resume event and knowing you were just ‘sending an email’ tell user thanks.
  6. Stop listening for resume event.

By ‘resume’ I mean specifically: ‘applicationResume’

https://docs.coronalabs.com/api/event/system/type.html

@roaminggamer

“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 doesn’t seem right.

You should get a resume event when the email client exits and you come back to Corona.

Interesting.   I’ll look at your code and if I have a suggestion, I’ll post back.

@kc,

I wrote my own example (pretty similar to yours) and it is working perfectly.

Please give this a look: 

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/03/emailPopup.zip

Try running the APK I built if you want: 

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/03/emailPopup_apk.zip

The big differences:

  • I define the system listener at the time the send function is called.
  • I also close the keyboard on resume.

I used SSK, but just because I like my button builder more than widget.*

@kc.thomas

Your example (minor change to provide a showThankYouMessage) worked for me … I see the applicationResume type of event.

Stan

@sieler2

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.

Any thoughts?

@kc … just to be sure… what platform are you running the app on?

I ran it on a Galaxy S7 Edge, Android 7.

Corona version  2017.3184 (2017.12.8)

@RG’s code ran fine on my Android, too.

@sieler

I am using an iPhone 5s (iOS 10.3.2).

I have not tested on an Android device yet, but this could certainly explain the difference in what we are experiencing.

Assuming it works on Android (both of you said it works), I still need a solution for iOS…

@kc,

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.

@rg although your question’s meant for @kc … I built from your example, thanks for posting it!

(And, I agree with your iOS comment!)

Stan

@RG

I copied your code to mine, then I built it and copied to my device, and ran it on my own device, so any behavior I observed is final.

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

@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. 

OK.  I built this for my iPad and tested it.  

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:

Add assertion: <BKProcessAssertion: 0x14de10ca0; id: 1178-DBBEC853-A808-4678-A988-65E67BBF73E0; name: systemAnimationFence; state: active; reason: finishTask; duration: 180.0s> {

    owner = <BSProcessHandle: 0x14de40110; MailComposition:1178; valid: YES>;

    flags = preventSuspend , preventThrottleDownCPU, preventSuspendOnSleep ;

To help confirm this I made a modified version of the example that prints out all system events to the screen:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/03/emailPopup2.zip

If the app were to suspend, you’d see this before clicking the ‘send email’ button (it says false because I’m capturing in simulator):

email_before.jpg

Then, after sending or cancelling the send you would see something like this IF THE APP SUSPENDED AND RESUMED :

email_after.jpg

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.)

Tip: You may be making this too hard.

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.

@roaminggamer
 

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 :slight_smile:

KC