Any success with iPhoneControlDo "execute" for scripts?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Any success with iPhoneControlDo "execute" for scripts?

Post by strongbow » Tue Sep 27, 2011 8:37 am

Has anyone successfully used

iphoneControlDo sBrowserId, "execute", pScript

to run some javascript in an embedded browser control (UIWebView)?

If so, then how? i.e. what format should the script be in?

Are there examples somewhere?

Thanks for any pointers!

cheers

Alan

rca
Posts: 16
Joined: Wed Aug 03, 2011 8:22 pm

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by rca » Sun Feb 19, 2012 12:15 am

I have had some success, but some challenges.. (assumes that the browser gMobBrowserID has already been created like
iphoneControlCreate "browser"
put the result into gMobBrowserID

This works on iOs:
put "alert('This is a message from the script');" into theFirstScript
iphoneControlDo gMobBrowserID, "execute", theFirstScript

also can do more than one line of JavaScript
put "alert('This is a message from the script');alert('This is another message from the script');" into theFirstScript
iphoneControlDo gMobBrowserID, "execute", theFirstScript

so I can execute multiple lines - even place the lines in a field for easier editing and visibility. (i.e. then "put field scriptData into theFirstScript")


BUT I can't get other simple things to work
alert(document.title);

will fail, with no error message in "the result"

In fact, if I have a field like
alert("This is a debugging message2");
alert("This is a debugging message3");
alert(document.title);

I don't get the first 2 alerts either - the whole statement fails

I find that these things (e.g. alert(document.title);) DO work on my mac, using get revBrowserExecuteScript(tBrowserId, theScript)
very frustrating....
I have tried using backslashes - doesn't work
For the lines above that do work, it seems to work with single quotes or double quotes on ios. They can have returns separating lines, in a field, or not...

also
according to Apple, "..JavaScript execution time is limited to 10 seconds .."

I need this to work for a project, so I will continue looking into it
I will try to post a test stack later today
r

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by strongbow » Sun Feb 19, 2012 10:07 am

Hi there

I did have success with this, but I haven't been using stuff like "document.title".. What I did have success with was calling Javascript functions that are in my web page from LiveCode. So basically the same as you but it has (so far) been enough for me.

For returning values to my app I attach them to the end of my URL from inside the Javascript function using

window.location = "#?returnVal="&myReturnVal

and then catch this in browserLoadRequest and handle it if necessary.

Hope this helps. :-)

rca
Posts: 16
Joined: Wed Aug 03, 2011 8:22 pm

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by rca » Sun Feb 19, 2012 5:31 pm

Hi Strongbow

Thanks for the feedback. Based on this forum, the live code Developer mailing list and support feedback, you and I are among the four people in the world trying to do this stuff. :-(
Surprising, as I think the internet is going to be BIG ;-), and Apple too..

I did post to another part of the forum, re "..you cannot exchange data in real time with JS in IOS browser.."
http://forums.runrev.com/viewtopic.php? ... 091#p52091

Calling a Javascript in the page is a good idea, and will work in some cases where I have control/input to the page, but for what I am trying to do that is not always a solution.
I will keep digging

btw I am Australian, living in California - good to see New Zealand, Australia active in these things
regards

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by strongbow » Sun Feb 19, 2012 7:07 pm

G'day there

Yup, as I have control over my page I can add functions etc as required. Also enables me to post stuff back to my LiveCode app that can then process it in "real-time"... :-) But, as you say, you have some other requirements. Haven't tried what you say so will be interested to see what you can come up with... will also let you know if I manage anything interesting.

Good luck in Cali - I'm a Kiwi in Germany... Drop in if you're over this way! ;-)

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by BarrySumpter » Tue Apr 24, 2012 10:15 pm

Hi strongbow,

Any way I can get you to post a sample app on how you are doing this?
i.e. posting back to LC app for real time processing?

tia
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by strongbow » Tue Apr 24, 2012 10:47 pm

Hi Barry

Well, the above bit explains one part of it:
For returning values to my app I attach them to the end of my URL from inside the Javascript function using

Code: Select all

window.location = "#?returnVal="&myReturnVal
and then catch this in browserLoadRequest and handle it if necessary.
The actual URL that you load could be on a website or even a local html file with included javascript functions.

To call a JS function from LC I just load a javascript function call into a variable and then call it using

Code: Select all

iphoneControlDo pBrowserId, "execute", pScript
where pBrowserId is the id of your iOS browser instance and pScript is the JS function, eg. computeDistance()

Inside that function, I would have the line:

Code: Select all

window.location = "#?returnVal="&myReturnVal
or something similar - this adds that string to the URL to be loaded. And then you catch that inside LC by handling:

Code: Select all

on browserLoadRequest pUrl, pReason
Here you would check if pURL contained the bits you added (i.e. returnVal=....) and if so, handle it inside LC.


I know this isn't that clear, probably a diagram of the process would be most understandable, but hope that it helps in some way.

cheers

Alan :-)

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by BarrySumpter » Tue Apr 24, 2012 11:16 pm

Hi Alan,

Many thanks for the reply.
Thanks for clarifying the logic behind this concept.

Where a picture is worth a thousand words,
a working sample app is worth a billion. :P

I'll know what to do when I get to the iOS version of my app.
Or when RR opens up the browser events for Android.

Thanks again.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

colourpixels
Posts: 83
Joined: Mon Oct 31, 2011 5:28 am

Re: Any success with iPhoneControlDo "execute" for scripts?

Post by colourpixels » Wed Jul 24, 2013 12:50 am

just thought I'd post that I found this thread very useful, using the technique to trigger animations created using Hype (HTML 5 editor). So thanks for the post.

Post Reply