Commit 88c66268 authored by Andre Natal's avatar Andre Natal Committed by GitHub
Browse files

Merge pull request #119 from andrenatal/links-on-webview

opening links in webview fixes #87 
parents 9ebc7a8f 2b5e4da3
......@@ -15,6 +15,7 @@
3E0027E31EC3C7870050B4AC /* voicebank_ios_wrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E0027E21EC3C7870050B4AC /* voicebank_ios_wrapperTests.swift */; };
3E0027EE1EC3C7870050B4AC /* voicebank_ios_wrapperUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E0027ED1EC3C7870050B4AC /* voicebank_ios_wrapperUITests.swift */; };
3E42BC791ECA43B8002E3CDA /* Recorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E42BC781ECA43B8002E3CDA /* Recorder.swift */; };
3EC11D911EF45B6D00589896 /* BrowserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EC11D901EF45B6D00589896 /* BrowserViewController.swift */; };
3EE991BC1ED8B81800432FC5 /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE991BB1ED8B81800432FC5 /* Reachability.swift */; };
/* End PBXBuildFile section */
......@@ -50,6 +51,7 @@
3E0027ED1EC3C7870050B4AC /* voicebank_ios_wrapperUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = voicebank_ios_wrapperUITests.swift; sourceTree = "<group>"; };
3E0027EF1EC3C7870050B4AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3E42BC781ECA43B8002E3CDA /* Recorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Recorder.swift; sourceTree = "<group>"; };
3EC11D901EF45B6D00589896 /* BrowserViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrowserViewController.swift; sourceTree = "<group>"; };
3EE991BB1ED8B81800432FC5 /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -109,6 +111,7 @@
3E0027D91EC3C7870050B4AC /* Info.plist */,
3E42BC781ECA43B8002E3CDA /* Recorder.swift */,
3EE991BB1ED8B81800432FC5 /* Reachability.swift */,
3EC11D901EF45B6D00589896 /* BrowserViewController.swift */,
);
path = "voicebank-ios-wrapper";
sourceTree = "<group>";
......@@ -270,6 +273,7 @@
files = (
3E42BC791ECA43B8002E3CDA /* Recorder.swift in Sources */,
3E0027D01EC3C7860050B4AC /* ViewController.swift in Sources */,
3EC11D911EF45B6D00589896 /* BrowserViewController.swift in Sources */,
3EE991BC1ED8B81800432FC5 /* Reachability.swift in Sources */,
3E0027CE1EC3C7860050B4AC /* AppDelegate.swift in Sources */,
);
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
......@@ -48,5 +48,52 @@
</objects>
<point key="canvasLocation" x="117.59999999999999" y="122.78860569715144"/>
</scene>
<!--Browser View Controller-->
<scene sceneID="mYR-zH-0e2">
<objects>
<viewController storyboardIdentifier="browser" id="e5D-wC-qEv" customClass="BrowserViewController" customModule="voicebank_ios_wrapper" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="hzT-eg-uJ6"/>
<viewControllerLayoutGuide type="bottom" id="qNb-bN-URg"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="MEM-1Y-qec">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kYJ-rj-xyT">
<rect key="frame" x="0.0" y="62" width="375" height="605"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="Fff-vQ-jUJ">
<rect key="frame" x="178" y="324" width="20" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</activityIndicatorView>
<navigationBar contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XjY-sT-7QT">
<rect key="frame" x="1" y="18" width="375" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<items>
<navigationItem id="w9l-cg-cFC">
<barButtonItem key="rightBarButtonItem" title="Close" id="bGA-oz-vkj">
<color key="tintColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<segue destination="BYZ-38-t0r" kind="show" id="2rU-fu-wab"/>
</connections>
</barButtonItem>
</navigationItem>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<connections>
<outlet property="activityIndicatorView" destination="Fff-vQ-jUJ" id="Hyu-Od-ynA"/>
<outlet property="plhview" destination="kYJ-rj-xyT" id="uga-SP-fTG"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FJ4-bY-kSf" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1012" y="122.78860569715144"/>
</scene>
</scenes>
</document>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
import Foundation
import UIKit
import WebKit
class BrowserViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView?
@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
@IBOutlet weak var plhview: UIView?
override func loadView() {
super.loadView()
print("constructor")
webView = WKWebView(frame: self.view.frame)
webView?.isHidden = true
webView?.navigationDelegate = self
webView?.scrollView.isScrollEnabled = true
self.plhview?.addSubview(webView!)
}
public func setUrl(url: String){
let _url = URL(string: url)
let request = URLRequest(url: _url!)
webView?.load(request)
}
func webView(_ webView: UIWebView, didFailLoadWithError error: Error)
{
}
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!) {
webView.isHidden = false
self.activityIndicatorView.isHidden = true
}
}
......@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>4</string>
<string>7</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMicrophoneUsageDescription</key>
......
......@@ -8,7 +8,8 @@ class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDele
var webView: WKWebView?
var recorder: Recorder!
var orientation: UIInterfaceOrientationMask!
var browserViewController: UIViewController? = nil
@IBOutlet weak var labelStatus: UILabel!
@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
......@@ -32,6 +33,8 @@ class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDele
// start the recorder object and ask permission to capture
recorder = Recorder()
recorder.webView = webView!
let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
browserViewController = mainStoryboard.instantiateViewController(withIdentifier: "browser")
}
}
......@@ -76,7 +79,7 @@ class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDele
return [UIInterfaceOrientationMask.portrait, UIInterfaceOrientationMask.portraitUpsideDown]
}
}
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!) {
webView.isHidden = false
......@@ -85,4 +88,20 @@ class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDele
webView.evaluateJavaScript("window.vcopensettings = function () { window.webkit.messageHandlers['scriptHandler'].postMessage('openSettings'); }")
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping ((WKNavigationActionPolicy) -> Void)) {
if (navigationAction.navigationType == WKNavigationType.linkActivated){
print(navigationAction.request.url?.relativeString as Any)
decisionHandler(WKNavigationActionPolicy.cancel)
self.present(browserViewController!, animated: true, completion: nil)
(browserViewController as! BrowserViewController).setUrl(url: (navigationAction.request.url?.absoluteString)!)
} else {
decisionHandler(WKNavigationActionPolicy.allow)
}
}
@IBAction func closeBrowserView() {
let prefs = UserDefaults.standard
prefs.setValue(0, forKey: "userDetails")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment