Return data from webview?

I’m wondering if it is possible to return data from a webview to my main application?

I’ve looked at the webview documentation here, http://docs.coronalabs.com/api/library/native/newWebView.html#overview and here http://docs.coronalabs.com/api/type/WebView/index.html , but don’t see how to accomplish this.

I don’t know what you mean by “return data.” If you mean have a bunch of items in the webview (perhaps drawn via Javascript), detect touches or taps on them, and then take some action, yes, that is possible and I’ve done it via a callback listener.

If you mean more extensive interaction, Corona isn’t designed for it and you might be better served with a different approach.

I want to open a native webview that I will use as a login form and get some json back from a web service.  I want to pass the data from the webview back to the corona app so I can store the data I received from the web service.  

Basic flow I’m looking for would be something like this.

Corona app opens

 -> Check if user is already logged in

    -> Yes?

       -> Continue to game

    -> No

       -> Open Webview login page

         -> User enters login info and clicks “Login”

           -> Wait for web service call to return with JSON/XML results

             -> Pass JSON/XML results back to Corona and continue with game 

You might be able to do that with Javascript. You definitely can do this with a mix of native and display objects and the network library. The One True Corona Way is to take the latter approach.

You might be able to do the former, but you’re working against The One True Corona Way and may not be able to get much help from the forums.

Yeah; I know it’s not the one true Corona way, but the embedded native components don’t look right in my game and I have found customizing them is way more difficult than it should be.  If I could swap in a WebView just for my login component then it would look like the rest of my game and I could do in an hour what I spent several days on in Corona and it still doesn’t look right.

If you choose to leave the straight, narrow, and rather painful path of The One True Corona Way, well, then I suspect whether you can do this or not depends on your command of Javascript.

You might be able to do something like:

local function webListener(event) local action = event.url:match (".-%?a=(.\*)$") if action then [etc]

But I haven’t done what you described. If you do manage to pull it off, perhaps you can share the technique you used.

I don’t know what you mean by “return data.” If you mean have a bunch of items in the webview (perhaps drawn via Javascript), detect touches or taps on them, and then take some action, yes, that is possible and I’ve done it via a callback listener.

If you mean more extensive interaction, Corona isn’t designed for it and you might be better served with a different approach.

I want to open a native webview that I will use as a login form and get some json back from a web service.  I want to pass the data from the webview back to the corona app so I can store the data I received from the web service.  

Basic flow I’m looking for would be something like this.

Corona app opens

 -> Check if user is already logged in

    -> Yes?

       -> Continue to game

    -> No

       -> Open Webview login page

         -> User enters login info and clicks “Login”

           -> Wait for web service call to return with JSON/XML results

             -> Pass JSON/XML results back to Corona and continue with game 

You might be able to do that with Javascript. You definitely can do this with a mix of native and display objects and the network library. The One True Corona Way is to take the latter approach.

You might be able to do the former, but you’re working against The One True Corona Way and may not be able to get much help from the forums.

Yeah; I know it’s not the one true Corona way, but the embedded native components don’t look right in my game and I have found customizing them is way more difficult than it should be.  If I could swap in a WebView just for my login component then it would look like the rest of my game and I could do in an hour what I spent several days on in Corona and it still doesn’t look right.

If you choose to leave the straight, narrow, and rather painful path of The One True Corona Way, well, then I suspect whether you can do this or not depends on your command of Javascript.

You might be able to do something like:

local function webListener(event) local action = event.url:match (".-%?a=(.\*)$") if action then [etc]

But I haven’t done what you described. If you do manage to pull it off, perhaps you can share the technique you used.