I need to render a web page offscreen to a bitmap, then show the bitmap to the user. Can this be done with simple code on the main thread like this:
NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[offscreenWebView loadRequest:requestObj];
Or do I need to attach the UIWebView to an active view?
In Android, the web view seems not to render unless it is part of an active view. So to do this task in Android, I need to create a view hierarchy, create an active view for the web renderer, and then put another view on top of it to let it draw offscreen.
I struggled with this problem for a while myself. UIWebView will not render unless it is added to a UIWindow object. However, this does not have to be the window you are using to show your app. You can make a separate UIWindow object, and attach the UIWebView to that and it will render just fine. However, UIWebView rendering is a slow process, so it will have a short delay before it is ready. When it is done, it will fire the webViewDidFinishLoad method to its delegate.