Reputation: 7705
My company uses a UIWebView
to display ads. The issue I'm having is that initializing a UIWebView
appears to be expensive; profiling with Time Profiler shows [UIWebView alloc] initWithFrame:CGRectMake(0,0,500,500)]
to take 31–40ms. This is enough to cause noticeable frame drops in games running at 60 FPS.
Is there a way to workaround this slow initialization time? My current ideas are to create a UIWebView
when the app launches (but before gameplay has started), and reuse that (potentially creating a pool of them to reuse, like how UITableViewCell
works) or to try and see if WKWebView
has better performance.
Upvotes: 3
Views: 1618
Reputation: 87
There is not much difference in the responsiveness between UIWebView
and WKWebView
because WKWebView
has been introduced for a consistency matter between iOS and OSX. The underlying engine is Webkit in either way and it requires a lot of initialization.
The best solution I've found recent during years has been fading a WebView
starting from a view with 0.1 alpha in which the url was loaded. Be careful to not start from 0.0 and do not have your webview detached from main view hierarchy because your url would not be loaded.
When didFinishLoading
is called then you can fade it to 1.0 thus providing a better user experience.
Personally I don't like the UIWebView
pool because I have experienced some memory troubles when maintaining it, especially on iOS 7 devices.
Upvotes: 1
Reputation: 7705
Here are my findings:
WKWebView
does not initialize any faster. Creating WKWebView
s took a similar amount of time as creating UIWebView
s (in the 1 test I did, it took 46ms to create two WKWebView
s.UIWebView
s was a good solution for my use case. By creating the webviews at app launch and then reusing them, I avoid causing a frame drop while the game is running.Upvotes: 6