Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Any Event Thrown When User Presses "Send" in native.showPopup("mail") ?
Started by kcdev Mar 07 2018 12:07 AM

19 replies to this topic
email native showpopup

Best Answer kcdev , 18 April 2018 - 04:26 PM

@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 :)

KC

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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.


[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

By 'resume' I mean specifically: 'applicationResume'

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



[TOPIC: post.html]
#4

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

@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



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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



[TOPIC: post.html]
#7

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

@kc.thomas

 

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

 

Stan



[TOPIC: post.html]
#8

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

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



[TOPIC: post.html]
#9

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

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



[TOPIC: post.html]
#10

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

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



[TOPIC: post.html]
#11

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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


Edited by roaminggamer, 08 March 2018 - 01:16 PM.


[TOPIC: post.html]
#12

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Contributor

  • 105 posts
  • Corona SDK

@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



[TOPIC: post.html]
#13

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

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



[TOPIC: post.html]
#14

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

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



[TOPIC: post.html]
#15

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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



[TOPIC: post.html]
#16

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

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

 



[TOPIC: post.html]
#17

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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. 



[TOPIC: post.html]
#18

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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


Edited by roaminggamer, 09 March 2018 - 11:26 AM.


[TOPIC: post.html]
#19

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

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.



[TOPIC: post.html]
#20

kcdev

[GLOBAL: userInfoPane.html]
kcdev
  • Contributor

  • 115 posts
  • Corona SDK

  Best Answer

@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 :)

KC




[topic_controls]
[/topic_controls]