I'm working on an app where there is a modal view containing a WKWebView. The webpage I'm displaying in the WKWebView is loaded via self.webView.loadHTMLString but the loading process takes too long, 5 seconds at times, and I would like to cut this time down significantly. Is there a way to preload this webpage (using loadHTMLString) so that when the modal is presented, the webpage is already loaded?
I've looked at all of the similar posts on Stack Overflow and none of them work in my case. The ways I've considered going about this are via caching and via calling setNeedsLayout in the viewDidLoad of the view controller that will present the modal, but haven't had any success. Any help would be greatly appreciated.
Related
I’m making an ios app using WKView and I notice that in some pages where there is a big amount of images to load, the webview feeze until the page completely loads all the images. (So, the User Can’t scroll until the page loads for 1 or 2 seconds)
In Safari mobile browser or in chrome this behavior is not happening. I’ve also add “loading=lazy” in all images, but didnt work.
Do you know how to fix this? I spent almost a week with this bug and I Didnt find any solution.
Thanks!
I'm trying to use a SFSafariViewController in the background to interact with cookies from a website. It seems that the pages is not loaded when the controller is not visible. Is that how it should be? What ways do I have to fix except than making sure the controller is always visible?
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use UIProgressView while loading of a UIWebView?
In my app i have a UIViewController with a UIWebView and a toolbar as a subviews.
The toolbar has a UITextField for the address. When loading a page the address field should indicate the loading progress of the webpage something like Safari's address bar or Facebook app for iOS when loading an external link.
The problem that i face is that i can't find a way to show the progress of the page when loading, making the address field(UIText field) fill with a color.
Is there any way to do that or a component already made for this?
To my knowledge there is no way that you could read the progress of a HTML page being loaded into an UIWebView. However I have an idea what you could do. It is a bit "around the corner" but if displaying a progress bar while loading a HTML page into a UIWebView is REALLY important to you, here is what you could do:
Do not load the HTML directly into the UIWebView. Load it into memory first (you can use the ASIHTTPRequest library to do that really easily).
ASIHTTPRequest offers a delegate method that allows you to access the progress of the request. Use that to display the progress.
Once the HTML finished loading, render it into the UIWebView using [UIWebView loadHTMLString:]
As I mentioned before this is really unconventional, but if you really need the progress to be displayed it is the only way I can think of.
I want to load few local html pages into UIWebview, but UIWebview is sometimes taking 2-3 seconds to load these pages the first time. I wanted to know how can I load couple of those pages at a time into memory prior to displaying through UIWebview? Is that possible?
Thanks for your help.
You could have a UIWebView in the same XIB as a normal view and hide it behind the normal view. Then, when the user needs to see the UIWebView, use this code:
[self.view bringSubviewToFront:webView];
I don't know if this is the best method, but it'll work. Now the UIWebView is actually open and actively loading a web page and the user doesn't even know.
I'm working on an app that has a series of hierarchical UITableViewControllers, until you are eventually taken to a UIWebView that contains the information you're looking for. It works fine except that when the UIWebView loads it takes a while to render and flashes white before loading (All my views, including the UITableViewControllers and HTML files, have a black background)
Once the UIWebView has been both loaded and displayed it's not so much a problem- I have it load up an empty HTML page with a black background while it loads the content- but the first time it's always slow, and gives me the white flash.
I've tried to pre-render the UIWebView by initializing it and loading it while the previous UITableViewController is still active, but it doesn't seem to work. It lets me define all the necessary parameters, but calling the loadView method, nor anything else I've tried, has cajoled it into actually loading up that black background HTML before it pushes the UIWebView on screen.
Ideally what I'd like it to do is just initialize the UIWebView in the background once the app starts, such that by the time it gets pushed onto the navigation stack for the user to see, it's already preloaded with that black background so there's no white flash.
How about webview.backgroundColor = [UIColor blackColor];?
Did you find and answer to this. I am doing the same thing. I have found I can create a second webview and start populating it off screen. I use javascript to check on the progress, so that I know it has rendered. However about 3 seconds after I have two pages rendered (one visible and one not) it thread for web pages crashes.
My next idea is to make both screen visible just most the unused screen a mile off to the right so the end user can't see it.