A WebViewController to display external and local content written in swift 5.0.
supported iOS Version +9.0
The WebViewController
needs to be initialized with a ContentType
.
ContentType can either be an external URL, a local HTML file in the application bundle or an HTML string.
let url = NSURL(string: "https://apple.com")!
let webView = WebViewController(content: .ExternalURL(url: url)) { controller in
controller.dismissViewControllerAnimated(true, completion: nil)
}
presentViewController(webView, animated: true, completion: nil)
The WebViewController can be configured to show progress and a navigation toolbar, as well as adopt to a specific tint color.
webView.showLoadingProgess = true
webView.showToolBar = true
webView.tintColor = .redColor()
WebViewController support a custom CSS to style your HTML content.
Call addCSS:bundle:
to inject a new CSS style.
App Transport Security (ATS) lets an app add a declaration to its Info.plist file that specifies the domains with which it needs secure communication. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.
If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible. If you want to display websites without https you have to enter the basepath in your
Info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
For more information about ATS go to: http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11
To integrate WebViewController into your Xcode project using Carthage, specify it in your Cartfile
github "allaboutapps/DataSource", ~> 4.1
This framework has to build with xcode8+
Current Swift compatibility breakdown:
Swift Version | Framework Version |
---|---|
5.2 | 4.1 |
5.0 | 3.1 |
4.0 | 3.0 |
3.0 | swift3 |
2.3 | 1.2 |
Open the Xcode project and press ⌘-U
to run the tests.
Alternatively, all tests can be run from the terminal using xctool.
xctool -scheme OAuthTests -sdk iphonesimulator test
Feel free to get in touch.