Use UIWebView in the background

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

How to do it?

+3
source share
3 answers

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

@property(nonatomic, getter=isHidden) BOOL hidden

Straght from class link :

. , , , . subviews , . .

, , .

. , , , .

+3

, - . .

self.backgroundWebView = [[[UIWebView alloc] initWithFrame:CGRectZero] autorelease];
[self.backgroundWebView loadRequest:[NSURLRequest requestWithURL:myURL]];
+3

Once you have launched webview, you can easily start a background thread that works with the view and loads the page.

[NSThread detachNewThreadSelector:@selector(connectToServer) toTarget:self
                               withObject:nil];

.....

(void) connectToServer
{
    // in a different thread....so we need a autoreleasepool
    NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
    ... // do your stuff
    // load HTML on webview
   [autoreleasepool release];
}
-2
source

Source: https://habr.com/ru/post/1709994/


All Articles