Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a UIWebView in the background

Tags:

iphone

I would like to use a UIWebView object to run custom javascript methods against a local web page. I can do that, but I would like to do it in the background, I mean, while I'm showing a navigation controller or any other content, load webpages and call javascript methods on them.

How would do that?

like image 282
Hectoret Avatar asked Nov 26 '25 22:11

Hectoret


2 Answers

I'm not sure what you mean by "in the background" but if you simply want the UIWebView to not be visible, this property is available on all UIView objects:

@property(nonatomic, getter=isHidden) BOOL hidden

Straght from the class reference:

A hidden view disappears from its window and does not receive input events. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual. Hiding a view with subviews has the effect of hiding those subviews and any view descendants they might have. This effect is implicit and does not alter the hidden state of the receiver’s descendants.

Hiding the view that is the window’s current first responder causes the view’s next valid key view to become the new first responder.

The value of this property reflects the state of the receiver only and does not account for the state of the receiver’s ancestors in the view hierarchy. Thus this property can be NO if the receiver is hidden because an ancestor is hidden.

like image 115
slf Avatar answered Nov 29 '25 14:11

slf


I was able to do this just by creating a web view in memory and never displaying it. It still exists and works fine.

self.backgroundWebView = [[[UIWebView alloc] initWithFrame:CGRectZero] autorelease];
[self.backgroundWebView loadRequest:[NSURLRequest requestWithURL:myURL]];
like image 20
Dave Batton Avatar answered Nov 29 '25 16:11

Dave Batton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!