meismyles / SwiftWebVC

A drop-in inline browser for your Swift iOS app.
MIT License
330 stars 117 forks source link

Blank screen with activity indicator issue for certain URL strings cases #24

Closed apparition47 closed 7 years ago

apparition47 commented 7 years ago

Version: 0.4.0

I noticed there are two cases where your module gets stuck on a blank screen with a spinning Activity Indicator (see screenshot):

simulator screen shot jun 12 2017 5 15 43 pm

  1. No schema

    let webVC = SwiftModalWebVC(urlString: "www.google.com")
  2. HTTP schema (not HTTPS)

    let webVC = SwiftModalWebVC(urlString: "http://www.google.com")

    I'm able to make this work if you create an iOS 8+ ATS exception for each HTTP domain or if you set NSAllowsArbitraryLoads.

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

My question is: is there any way to allow HTTP links on WKWebView without doing the above?

Thanks!

meismyles commented 7 years ago

In terms of No Schema you are probably right there - this library should probably handle URL's without needing it to be specified so I will add that in.

In terms of HTTP vs HTTPS, unfortunately this is app specific and so if you want to use HTTP you will need to specify the keys you mentioned above manually. Also bear in mind that it appears Apple will be moving to enforce HTTPS usage in all apps at some point in the near future. This was originally scheduled to be brought in at the end of 2016 but was subsequently delayed with a now open ended deadline - but moving everything to HTTPS sooner rather than later is probably a good move. See here.

apparition47 commented 7 years ago

Thanks for the quick response. I thought about (2) a bit more after posting and I think you're right. I was confused at first because no error message. 0.1.2 with UIWebView logs:

SwiftWebVCExample[23423:1550909] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

but I guess that has more to do with UIWebView behaviour itself.

meismyles commented 7 years ago

Not just loading pages using UIWebView or WKWebView, even just basic web connections are protected by ATS, e.g. NSURLConnection, URLSession, etc. It's essentially a system service protecting against any external connections it deems as insecure. So yeah, the only way around it is to set the keys in your Info.plist and tell the OS you know these connections are potentially insecure, but you are happy to still make them.

apparition47 commented 7 years ago

Yes, you're right. But since my target is iOS 9+, I discovered I can use SafariServices to open an inline browser for http:// URLs in my app.

import SafariServices

let svc = SFSafariViewController(url: URL(string: "http://www.google.com")!)
present(svc, animated: true, completion: nil)

Thanks again!