Send SMS, call Phonenumber or Mailmessage from webpopup in Corona works!!!

Hey everyone
I have create a Corona app that uses the tab bar at the bottom of the app. But then I have so much stuff that must rely on serverside so I decided to create webviews for all tabs and the only thing I do is that I send in the DEVICE ID on all requests so I know which client/device is requesting the data.

This works great and here is the code for it.

[lua]native.showWebPopup( 0, 0, 320, 436,
http://servername/mobile/displayInfopage?uid=” … deviceID)[/lua]

But now when I created a mobile webpage with links on it to tel, sms and mailto the only one worked was tel. So I decided to dig into this a lot and I didn’t find any post on how to actually solve this in some smart and neat way.

Today I did solve it though and I thought I would share it with you.

When calling the showWebPopup you can add a listener to that call that will actually get called on all clicks and urls clicked on in every webpage you load inside the webview.

So I created a little listener that will take the url on this particular page and instead of trying to open them in the webpopup I use the System.openURL and VOILA all of them works perfectly.

Complete code sample below

[lua] local function listener( event )
local shouldLoad = true
local url = event.url
system.openURL( url )
return shouldLoad
end

native.showWebPopup( 0, 0, 320, 436,
http://servername/mobile/displayInfopage?uid=” … deviceID,
{urlRequest=listener} )[/lua]

and in the mobile webpage on the server which is opened above I can now call mailto, tel or sms and it will open and prefill in the case that works with no problems.

The only thing that irritates me a bit is that I would like to return to my app after sending the sms is done or after the mail get sent but I haven’t been able to solve this just yet.

Have fun! [import]uid: 22737 topic_id: 18446 reply_id: 318446[/import]

I’m somewhat lost on your solution here. We are trying to also invoke sending SMS with pre-filled phone, and body - but when we pass through a website nothing goes with it. Accourding to other tests we’ve done none of this works using [
So, would you post an example of your web landing page that is processing the pre-fill for you, that would help clear things up.

[import]uid: 9046 topic_id: 18446 reply_id: 71267[/import] ](sms:…)

Let’s say you have a plain HTML or any other server-side webpage on your webserver and inside that page you have some a href links with links like tel:, sms: or mailto but in your case you have sms: followed by a number.

You cannot prefill body in sms messages yet with links, that can only be accomplish within pure objective-c in XCode or some other studio software but not from Corona SDK since they do not support that yet.

Let’s say you have a link like sms:+46722256015 which is my private cellphone number.

The below code is within the page ServerSide.html

[Send message to Andreas](sms:+46722256015)  

Then inside your Corona LUA file which opens the webpage above you will have.

[lua]local function listener( event )
local shouldLoad = true
local url = event.url
system.openURL( url )
return shouldLoad
end

native.showWebPopup( 0, 0, 320, 436,
http://servername/ServerSide.html”,
{urlRequest=listener} )[/lua]
So the above lua-code will open the webpage from your server and show the link to sending a sms to me. When that link is clicked the serverside webpage will callback to your lua file and to the function listener and the url clicked will be stored in event.url.

I just open the event.url with the native system.openURL which will open the message application or any other application associated with that link prefix.

Does it make any sense? Sorry for being blurry :slight_smile: I just went so happy when solving this issue. [import]uid: 22737 topic_id: 18446 reply_id: 71435[/import]

By device ID, do you mean UDID? If so, Apple doesn’t want devs to use that anymore:
http://techcrunch.com/2011/08/19/apple-ios-5-phasing-out-udid/
[import]uid: 1560 topic_id: 18446 reply_id: 71438[/import]

I understand what you are doing now, and to be honest I still don’t know why you are doing it in such a way. Simply using a [lua]system.openURL( “sms:11111111” )[/lua] would do the trick - you don’t have to pass it to a website then back into a listener.
You are right in that Corona doesn’t support pre-filling those elements, actually I don’t think it was until iOS4 that devs could do that in Xcode (which we’ve done multiple times in other “non-Corona” apps.

Anyway, thanks for the clarification of your method but I think you are taking the long way around.

Rich
[import]uid: 9046 topic_id: 18446 reply_id: 71441[/import]

The reason I want it this way or actually have to do it this way is that I have to initiate the Send SMS from a webpage on my server because that part of the application is a webpage so I can’t use system.openURL that way. [import]uid: 22737 topic_id: 18446 reply_id: 71446[/import]

Now you can do it from within your app, and prefill values from within your app!

Mail is available in the current daily build. SMS will be in tomorrow’s daily build (2011.712 or after).

Check out the updated doc:

http://developer.anscamobile.com/reference/index/nativeshowpopup

Enjoy! [import]uid: 26 topic_id: 18446 reply_id: 75031[/import]