A day with Cordova and iOS WKWebView

A

Well, 

Never thought I’ll work on a Cordova project, But here I am writing about it. Recently I have been working on a migration project which uses Cordova in the frontend and parse for the backend. (I know, please don’t ask)

I have been rewriting the whole parse backend in python since last past couple of months, and finally it was the time to replace the server logic in the frontend app (Cordova)

All the api calls using Axios worked fine for the web and mobile till I came across the weird issue where api calls from the iOS app was not going through at all.

Time to debug

Step 1 – Check why the request was not going through

Is it because CORS ? Well iOS apps don’t need CORS right. Turns out they do.

WKWebView is a replacement to iOS’s legacy UIWebView which is supposed to be deprecated after iOS 13 release. Probably this is the right time for people who was using UIWebView to pledge their allegiance to WKWebView. WKWebView supposedly more secure than UIWebView and uses apples Web Kit engine to its core.

BTW, you should never come across this issue of iOS apps not be able to calls the rest api’s if you’re using UIWebView

Below is a sample request on how the request is sent to the server when you use WKWebView to call REST API’s followed by an network error in comment.

If you closely look at the sourceURL it sends a file://

Step 2 – The solution to the problem

If you use CORS in the server most of the times we only include HTTP or HTTP urls in the CORS setting. So when we get a scenario like this where WKWebView is sending file:// protocol the server will not be able to understand and automatically reject the request.

Well there is no solution from the app side. You have to update your server CORS settings. To solve the problem you have to append the value null to the list of urls your CORS setting has. Look at he example below

This is solve the problem of api calls not going through in iOS apps.

Happy Debugging

About the author

Subodh Jena

I'm an open minded liberal type with curiosity as perhaps my main motivator. I love science, art, the natural world and learning from people of diverse backgrounds.

Add comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest updates

Subscribe to Blog