I have a WKWebView to load a website that has a custom url scheme (mycustomurl://) implemented with WKURLScheme, which the website will call using GET. Everything works as expected when the website is in http://, but breaks when I switch to https:// with the following error:
[blocked] The page at https:// (url snipped) was not allowed to display insecure content from mycustomurl://(url snipped).
The WKURLScheme callback was never hit, so I suspect Safari or higher power blocked it :/
I already comb through SO discussions on ATS, none of it worked. I did saw some discussions like this one that mentioned this is because Safari blocks mixed content, and when I tried it directly on Safari it did generate the same result (blocked).
There seems to be no solution to this? It seems we can't turn off Safari's mixed content restriction. Then how should custom URL scheme be used and implemented because https should always a better choice than http?
I did notice most custom URL scheme tutorials have http instead of https...
Not sure this answer is still relevant but an actual working solution is to use a custom WKUrlSchemeHandler
to load the initial https-page from.
I recently faced a similar issue (trying to connect to a WebSocket server on device from a https-page) and the only way I found to get this working while still keeping the application secured by https was the following not-so-nice workaround:
WKUrlSchemeHandler
for mycustomurl://
WKUrlSchemeHandler
, let's say myapp-remote://
webView:startURLSchemeTask:
:
urlSchemeTask.Request
myapp-remote://
with https://
NSURLDataRequest
with the https-urlurlSchemeTask
With this setup you can fetch your https-Page by using myapp-remote://
as schema for the initial load, keeping TLS security as well as validation and also have working mycustomurl://
references that your WKWebView
won't block.
My implementation is in C# for Xamarin but I can provide it for clarity if it's needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With