Skip to content
This repository was archived by the owner on Feb 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions FLWebViewSwift/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand All @@ -11,16 +12,16 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2014 Float Mobile Learning. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2016 Float. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="FLWebViewSwift" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
8 changes: 4 additions & 4 deletions FLWebViewSwift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="UYf-Xx-dJ5">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="UYf-Xx-dJ5">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--Web View-->
Expand All @@ -14,9 +14,9 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" title="Web View" id="rhq-zE-XQl"/>
</viewController>
Expand Down
11 changes: 7 additions & 4 deletions FLWebViewSwift/FLUIWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension UIWebView: FLWebViewProvider {
delegate = viewController
}

func canNavigateBackward() -> Bool {
func canNavigateBack() -> Bool {
return self.canGoBack
}

Expand All @@ -30,12 +30,15 @@ extension UIWebView: FLWebViewProvider {
return self.request?.URL
}

func evaluateJS(javascriptString: String!, completionHandler: (AnyObject, NSError) -> ()) {
func evaluateJavaScriptString(javascriptString: String!, completionHandler: (AnyObject?, NSError?) -> ()) {
// Have the WebView evaluate the javascript string
let string = stringByEvaluatingJavaScriptFromString(javascriptString)
guard let string = stringByEvaluatingJavaScriptFromString(javascriptString) else {
completionHandler(nil, nil)
return
}

// Call the completion handler from there
completionHandler(string!, NSError(domain: "FLWebView", code: 200, userInfo: nil))
completionHandler(string, nil)
}

func setScalesPageToFit(setPages: Bool!) {
Expand Down
19 changes: 8 additions & 11 deletions FLWebViewSwift/FLWKWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ extension WKWebView: FLWebViewProvider {
return objc_getAssociatedObject(self, associatedObjectKey()) as? NSURLRequest
}
set(newValue) {
objc_setAssociatedObject(self, associatedObjectKey(), newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
objc_setAssociatedObject(self, associatedObjectKey(), newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}

// A simple convenience initializer, this allows for WKWebView(delegateView:) initialization
convenience init(delegateView: AnyObject) {
self.init()
self.UIDelegate = delegateView as? WKUIDelegate
self.navigationDelegate = delegateView as? WKNavigationDelegate
convenience init(delegateView: ViewController) {
self.init(frame: delegateView.view.frame, configuration: WKWebViewConfiguration())
setDelegateViews(delegateView)
}

// We will need to set both the UIDelegate AND navigationDelegate in the case of WebKit
Expand All @@ -35,7 +34,7 @@ extension WKWebView: FLWebViewProvider {
return self.URL
}

func canNavigateBackward() -> Bool {
func canNavigateBack() -> Bool {
return self.canGoBack
}

Expand All @@ -48,10 +47,8 @@ extension WKWebView: FLWebViewProvider {
self.loadRequest(NSURLRequest(URL: NSURL(string: urlNameAsString)!))
}

// Pass this up the chain and let WebKit handle it
func evaluateJS(javascriptString: String!, completionHandler: (AnyObject, NSError) -> ()) {
self.evaluateJavaScript(javascriptString, completionHandler: { (AnyObject, NSError) -> Void in

})
func evaluateJavaScriptString(javascriptString: String!, completionHandler: (AnyObject?, NSError?) -> ()) {
evaluateJavaScript(javascriptString, completionHandler: completionHandler)
}

}
5 changes: 3 additions & 2 deletions FLWebViewSwift/FLWebViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ protocol FLWebViewProvider: class {

func loadRequestFromString(urlNameAsString: String!)

func canNavigateBackward() -> Bool
func canNavigateBack() -> Bool

func canNavigateForward() -> Bool

func evaluateJS(javascriptString: String!, completionHandler: (AnyObject, NSError) -> ())
func evaluateJavaScriptString(javascriptString: String!, completionHandler: (AnyObject?, NSError?) -> ())

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
4 changes: 4 additions & 0 deletions FLWebViewSwift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<array>
<string>armv7</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
25 changes: 9 additions & 16 deletions FLWebViewSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,26 @@ import WebKit
class ViewController: UIViewController, UIWebViewDelegate, WKNavigationDelegate, WKUIDelegate {

var webView: FLWebViewProvider?

override func viewDidLoad() {
super.viewDidLoad()


override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// Check if WKWebView is available
if #available(iOS 8.0, *) {
let w = WKWebView(delegateView: self)
w.frame = self.view.frame
w.frame = CGRect(origin: CGPointZero, size: self.view.frame.size)
self.webView = w
self.view.addSubview(self.webView as! WKWebView)
} else {
// In this case we have to fall back on UIWebView
// Fallback on earlier versions
let w = UIWebView(delegateView: self)
w.frame = self.view.frame
w.frame = CGRect(origin: CGPointZero, size: self.view.frame.size)
self.webView = w
self.view.addSubview(self.webView as! UIWebView)
}

self.view.addSubview(self.webView as! UIView)

// Load a page, in this case we will load our favorite website
self.webView?.loadRequestFromString("https://www.google.com/")
self.webView?.loadRequestFromString("http://www.gowithfloat.com")
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}