If you would prefer to watch a video instead, you can check it out below!
At Embrace, we help mobile companies solve their most difficult production issues. In this series, we’ll cover interesting bugs that mobile developers might come across, and we’ll provide tips and tricks for finding and fixing them.
Here’s a screenshot from one of our partner’s mobile apps.
The iOS process model
On iOS, most applications have one and only one process. You have a main thread, and you can spawn other threads to do background work like networking tasks or rendering. But on the whole, your application is running in a single process.
This allows the operating system to better manage resources. If your application is using too much memory, your application can be suspended or terminated to free up resources for other applications on the system. But this changes when you introduce WebKit into your app.
WKWebView actually uses a multi-process model to render its pages, just like the Safari app does on your desktop.
What this means is your user could be using your application to check out items from your store or read comments on a forum, and all of a sudden all of those items or comments just disappear. This can be incredibly frustrating for your users as it doesn’t crash your application. To your user it looks like your app is still running but the content just disappeared. This is kind of the worst case scenario, so how can you avoid this?
Luckily, Apple thought about this and provides an API on WKWebView to handle blank web views. First, you should be implementing WKNavigationDelegate, which is a navigation delegate that provides a series of callbacks that can help you manage what’s going on with the content on your web views. You’ll know when the load started, when the load stopped, if your user clicks any links on the page, etc. But there’s an extra method on here that you probably have never looked at or implemented and that is
If you implement that callback, the system will tell you when the content process of any of your web views is killed, and you’ll have a chance to react to that event. Sometimes you may decide to hide that web view if it’s an advertisement or something that you’re not able to fix yourself. But if it’s your storefront or your checkout page, you can reload the page because chances are your user was trying to do something and would like to continue doing their work. By simply reloading the page, they can keep going and often that is the best solution.
Summing it all up
In this post, we covered blank web views on iOS applications. They occur when web views fail or are killed by the OS. Normally, a process being killed would crash the application, but on iOS, WKWebViews have two additional processes: a content process and a networking process. These can be killed without affecting the main application process. You can provide a better user experience by deciding which web views should be reloaded upon failure and adding this functionality through the
webViewWebContentProcessDidTerminate callback on WKNavigationDelegate.
We hope you found this post helpful and are empowered to take action on how your application responds to blank web views going foward.
Who we are
Deliver incredible mobile experiences with Embrace.
Get started today with 1 million free user sessions.Get started free