Why does UIWebView say “URL can't be shown” when trying to open an URL for another app when it works in Safari?

Trying to fix an old IOS APP where UIWebView won't open an URL to another app. The app says "URL can't be shown", which might indicate the URL is wrong, but i am able to open it directly in Safari.

Hello, I received the responsibility for fixing an app for my company and I do not have much experience with Objective-c, so I hope you can help me. The app have previously worked, but suddenly stopped working in 2016. This is probably because of an updated that happened at this time, which changed some functionality. The app opens a UIWebView and through this access a webservice from where the user can input some information etc. This webservice then calls another app to print a label, but instead just displays a pop up with “URL can’t be shown”.

When I write this URL directly into Safari, it opens the app and works with no problems. This made me think the problem might be somewhere in UIWebView, but I cannot locate exactly where this might be.

I do not know what cope snippet or information might be worth including, but if you ask what you need I can provide it.

Replies

Safari and various web views have, over the years, received a number of security changes related to opening external URLs. I’m not sure exactly what change is affecting your app, but the way forward is clear. Your app should implement the

-webView:shouldStartLoadWithRequest:navigationType:
delegate method, watch for the URL you care about, and open it with native code (for example, by calling
-[UIApplication openURL:]
).

ps Given that you’re wading into the code to fix this, you should take the opportunity to switch to

WKWebView
. In most cases it’s a simple replacement for
UIWebView
, and the latter has been officially deprecated because its architecture makes it impossible to implement certain security mitigations (see WWDC 2018 Session 207 Strategies for Securing Web Content for more on this).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,

I tried implementing the delegat method suggested with no luck. I am not sure what else can be causing the issues.

I don't feel i have the skills to replace UIWebView in the current state of the applikation, but i will look into this later 🙂

Thanks for the input so far and if you have any other ideas as to what culd be causing the issues i am open.

I tried implementing the delegat method suggested with no luck.

Can you be more specific about what “no luck” means? Is your delegate method called at all? If so, is it called for this specific URL?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"