Is it possible to access the contents of an iOSHTMLViewer?

Hi.

Just getting started with the iOS features here and was wondering if there’s any way to read the contents of an iOSHTMLViewer - i.e. my thought was to get the html viewer to get the location of the iOS device (which I’m supposing it ought to be able to do), display it in plain text and then parse the results for the purposes of the rest of the app I’m trying to build. So far all I can see is that the viewer takes a URL and displays it (if possible) and that’s it, nothing else: no way to read back the ‘insides’ of the control.

Is it possible or am I chasing my tail?

There’s nothing built-in that lets you do that. There might be some declares you could use but you’d have to look at Apple’s documentation.

I just looked yesterday at UIWebView Class reference in Apple Dev Library at https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/index.html#//apple_ref/occ/cl/UIWebView

I wanted to see how to implement CancelLoad and the Title property, but could not find anything that resembles.

I may be mistaken, but there seem to be no way either to access the DOM.

The only hope may be using JavaScript through stringByEvaluatingJavaScriptFromString: to get that content. Although it is not quite clear how one is supposed to inject JavaScript into the Dom. Plus there are limits :

Same thing for Document.Title and maybe one could catch the click on a link to do sort of a CancelLoad.

It is not terribly encouraging :frowning:

You need to set the UIWebview’s delegate object then implement the delegate methods:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/index.html#//apple_ref/occ/intf/UIWebViewDelegate

It shouldn’t be too hard.

[quote=153783:@Jason King]You need to set the UIWebview’s delegate object then implement the delegate methods:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/index.html#//apple_ref/occ/intf/UIWebViewDelegate

It shouldn’t be too hard.[/quote]

I am a lot better at reading what a class can do than creating the declares. Actually, it has become easier for me since Swift, as I am better able to understand how it works than all too esoteric for me OC.

I have never created a delegate. I am just barely able to set or get a property. Maybe with the help of your DeclareMaker I still have to try (thank you!). I will probably try tomorrow.

From what I can read, though, webView:shouldStartLoadWithRequest:navigationType: does provide the CancelLoad functionality, but no window title, or obvious access to the DOM. That class seems awfully limited.

I have been thinking about making a post about creating a delegate like this for a while. DeclareMaker doesn’t have the ability to create a delegate right now, but honestly it is fairly easy so a post explaining it would probably suffice. Let me see what I can do in the coming days, my plate is kind of fully right now…

No hurry, Jason, but I am sure if you shared your insight, I would not be the only one to deeply appreciate it :slight_smile:

I’ll plan to put a post together in few days. In the mean time, here is your cancel load event (and Error and Document complete/begin):
https://www.dropbox.com/s/8zkqzgm3w55umr1/htmlviewer%20extension.xojo_binary_project?dl=0
If you wanted you could wrap the delegate class in an HTMLViewer subclass so that everything is contained in one class, but I’ll leave that up to you.

[quote=154521:@Jason King]I’ll plan to put a post together in few days. In the mean time, here is your cancel load event (and Error and Document complete/begin):
https://www.dropbox.com/s/8zkqzgm3w55umr1/htmlviewer%20extension.xojo_binary_project?dl=0
If you wanted you could wrap the delegate class in an HTMLViewer subclass so that everything is contained in one class, but I’ll leave that up to you.[/quote]

Beautiful. Jason, you rock !

Thank you.

Michel,
Thank you for sharing this code. It adds much needed events.

I’m using the DocumentComplete event from your sample. How should I properly handle this to stop it from firing after I have closed my view?

If I close the view with a HTML request in place then this event gets fired after I have closed the view and got rid of the HTMLViewer, creating a Nil Object Exception.

Almost one month after the last entry here: @David, did you solve that issue? If you maintain a separate delegate, it should check for the existence of its parent control before it tries to call a method on it.
In many cases, mostly those where the class does not retain the delegate, I find it much easier to implement the delegate methods on the control itself. Gets you rid of complicated delegate object retainment and eliminates Nil exceptions.

Absolutely Great!!