diff --git a/Example/SwiftWebVCExample.xcodeproj/project.pbxproj b/Example/SwiftWebVCExample.xcodeproj/project.pbxproj
index 283ba5c..2280842 100644
--- a/Example/SwiftWebVCExample.xcodeproj/project.pbxproj
+++ b/Example/SwiftWebVCExample.xcodeproj/project.pbxproj
@@ -162,6 +162,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
+ English,
en,
Base,
da,
@@ -302,7 +303,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -353,7 +354,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -366,12 +367,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CURRENT_PROJECT_VERSION = 0.5.0.0;
INFOPLIST_FILE = SwiftWebVCExample/Info.plist;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ MARKETING_VERSION = 0.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.swiftweb.SwiftWebVCExample;
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 4.0;
+ SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -379,12 +382,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CURRENT_PROJECT_VERSION = 0.5.0.0;
INFOPLIST_FILE = SwiftWebVCExample/Info.plist;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ MARKETING_VERSION = 0.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.swiftweb.SwiftWebVCExample;
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 4.0;
+ SWIFT_VERSION = 5.0;
};
name = Release;
};
diff --git a/Example/SwiftWebVCExample/AppDelegate.swift b/Example/SwiftWebVCExample/AppDelegate.swift
index 818c74b..ce7838b 100644
--- a/Example/SwiftWebVCExample/AppDelegate.swift
+++ b/Example/SwiftWebVCExample/AppDelegate.swift
@@ -13,8 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
-
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
@@ -40,7 +39,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-
-
}
-
diff --git a/Example/SwiftWebVCExample/Info.plist b/Example/SwiftWebVCExample/Info.plist
index 9cf8240..2439d9e 100644
--- a/Example/SwiftWebVCExample/Info.plist
+++ b/Example/SwiftWebVCExample/Info.plist
@@ -15,9 +15,9 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 0.4.2
+ $(MARKETING_VERSION)
CFBundleVersion
- 0.4.2.0
+ $(CURRENT_PROJECT_VERSION)
LSRequiresIPhoneOS
UILaunchStoryboardName
diff --git a/Example/SwiftWebVCExample/ViewController.swift b/Example/SwiftWebVCExample/ViewController.swift
index 0a5de3c..c83c82e 100644
--- a/Example/SwiftWebVCExample/ViewController.swift
+++ b/Example/SwiftWebVCExample/ViewController.swift
@@ -10,6 +10,8 @@ import UIKit
class ViewController: UIViewController {
+ fileprivate let testUrlString = "https://www.google.com"
+
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
@@ -22,24 +24,24 @@ class ViewController: UIViewController {
// MARK: Push
@IBAction func push() {
- let webVC = SwiftWebVC(urlString: "https://www.google.com")
+ let webVC = SwiftWebVC(urlString: testUrlString)
webVC.delegate = self
self.navigationController?.pushViewController(webVC, animated: true)
}
// MARK: Modal
@IBAction func presentModalWithDefaultTheme() {
- let webVC = SwiftModalWebVC(urlString: "www.google.com")
+ let webVC = SwiftModalWebVC(urlString: testUrlString)
self.present(webVC, animated: true, completion: nil)
}
@IBAction func presentModalWithLightBlackTheme() {
- let webVC = SwiftModalWebVC(urlString: "https://www.google.com", theme: .lightBlack, dismissButtonStyle: .cross)
+ let webVC = SwiftModalWebVC(urlString: testUrlString, theme: .lightBlack, dismissButtonStyle: .cross)
self.present(webVC, animated: true, completion: nil)
}
@IBAction func presentModalWithDarkTheme() {
- let webVC = SwiftModalWebVC(urlString: "https://www.google.com", theme: .dark, dismissButtonStyle: .arrow)
+ let webVC = SwiftModalWebVC(urlString: testUrlString, theme: .dark, dismissButtonStyle: .arrow)
self.present(webVC, animated: true, completion: nil)
}
@@ -48,10 +50,10 @@ class ViewController: UIViewController {
extension ViewController: SwiftWebVCDelegate {
func didStartLoading() {
- print("Started loading.")
+ debugPrint("Started loading.")
}
func didFinishLoading(success: Bool) {
- print("Finished loading. Success: \(success).")
+ debugPrint("Finished loading. Success: \(success).")
}
}
diff --git a/README.md b/README.md
index a5d3f5a..d57e65b 100755
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ SwiftWebVC is a simple inline browser for your Swift iOS app.
* Full landscape orientation support
* Back, forward, stop/refresh and share buttons
* Open in Safari and Chrome UIActivities
-* Navbar title set to the currently visible web page
+* Navbar title set to the currently visible web page or address bar for navigation
* Talks with `setNetworkActivityIndicatorVisible`
* 3 different themes to choose from when presented modally
@@ -68,13 +68,17 @@ self.present(webVC, animated: true, completion: nil)
### Options
+The address bar can be replaced with the site title by passing a flag in to the constructor:
+```swift
+let webVC = SwiftWebVC(urlString: "http://google.com", showAddressBar: false)
+```
The share button can be disabled by passing a flag in to the constructor to specify this:
```swift
let webVC = SwiftWebVC(urlString: "http://google.com", sharingEnabled: false)
```
The same principal applies for the modal implementation also:
```swift
-let webVC = SwiftModalWebVC(urlString: "http://google.com", sharingEnabled: false)
+let webVC = SwiftModalWebVC(urlString: "http://google.com", sharingEnabled: false, showAddressBar: true)
```
#### Modal Options Only
@@ -85,8 +89,6 @@ let webVC = SwiftModalWebVC(urlString: "http://google.com", theme: .lightBlack)
let webVC = SwiftModalWebVC(urlString: "http://google.com", theme: .dark)
```
-
-
## Delegate (Start/Finish Loading Callbacks)
SwiftWebVC also includes a delegate protocol that allows you to implement `didStartLoading` and `didFinishLoading` functions to determine when loading starts and finishes.
diff --git a/SwiftWebVC.podspec b/SwiftWebVC.podspec
index ce6c4e2..bf299e7 100755
--- a/SwiftWebVC.podspec
+++ b/SwiftWebVC.podspec
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'SwiftWebVC'
- s.version = '0.4.2'
+ s.version = '0.5.0'
s.summary = 'SwiftWebVC is a simple inline browser for your Swift iOS app.'
# This description is used to generate tags and improve search results.
@@ -38,7 +38,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/meismyles/SwiftWebVC.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/'
- s.ios.deployment_target = '8.0'
+ s.ios.deployment_target = '10.0'
s.source_files = 'SwiftWebVC/**/*.swift'
diff --git a/SwiftWebVC/SwiftModalWebVC.swift b/SwiftWebVC/SwiftModalWebVC.swift
index 22ff7ef..c0dff78 100755
--- a/SwiftWebVC/SwiftModalWebVC.swift
+++ b/SwiftWebVC/SwiftModalWebVC.swift
@@ -19,34 +19,63 @@ public class SwiftModalWebVC: UINavigationController {
weak var webViewDelegate: UIWebViewDelegate? = nil
- public convenience init(urlString: String, sharingEnabled: Bool = true) {
+ public convenience init(urlString: String,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
var urlString = urlString
if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") {
urlString = "https://"+urlString
}
- self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled)
+ self.init(pageURL: URL(string: urlString)!,
+ sharingEnabled: sharingEnabled,
+ showAddressBar: showAddressBar)
}
- public convenience init(urlString: String, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) {
- self.init(pageURL: URL(string: urlString)!, theme: theme, dismissButtonStyle: dismissButtonStyle, sharingEnabled: sharingEnabled)
+ public convenience init(urlString: String,
+ theme: SwiftModalWebVCTheme,
+ dismissButtonStyle: SwiftModalWebVCDismissButtonStyle,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
+ self.init(pageURL: URL(string: urlString)!,
+ theme: theme,
+ dismissButtonStyle: dismissButtonStyle,
+ sharingEnabled: sharingEnabled,
+ showAddressBar: showAddressBar)
}
- public convenience init(pageURL: URL, sharingEnabled: Bool = true) {
- self.init(request: URLRequest(url: pageURL), sharingEnabled: sharingEnabled)
+ public convenience init(pageURL: URL,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
+ self.init(request: URLRequest(url: pageURL),
+ sharingEnabled: sharingEnabled,
+ showAddressBar: showAddressBar)
}
- public convenience init(pageURL: URL, theme: SwiftModalWebVCTheme, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle, sharingEnabled: Bool = true) {
- self.init(request: URLRequest(url: pageURL), theme: theme, dismissButtonStyle: dismissButtonStyle, sharingEnabled: sharingEnabled)
+ public convenience init(pageURL: URL,
+ theme: SwiftModalWebVCTheme,
+ dismissButtonStyle: SwiftModalWebVCDismissButtonStyle,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
+ self.init(request: URLRequest(url: pageURL),
+ theme: theme,
+ dismissButtonStyle: dismissButtonStyle,
+ sharingEnabled: sharingEnabled,
+ showAddressBar: showAddressBar)
}
- public init(request: URLRequest, theme: SwiftModalWebVCTheme = .lightBlue, dismissButtonStyle: SwiftModalWebVCDismissButtonStyle = .arrow, sharingEnabled: Bool = true) {
+ public init(request: URLRequest,
+ theme: SwiftModalWebVCTheme = .lightBlue,
+ dismissButtonStyle: SwiftModalWebVCDismissButtonStyle = .arrow,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
let webViewController = SwiftWebVC(aRequest: request)
webViewController.sharingEnabled = sharingEnabled
webViewController.storedStatusColor = UINavigationBar.appearance().barStyle
+ webViewController.showAddressBar = showAddressBar
let dismissButtonImageName = (dismissButtonStyle == .arrow) ? "SwiftWebVCDismiss" : "SwiftWebVCDismissAlt"
let doneButton = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: dismissButtonImageName),
- style: UIBarButtonItemStyle.plain,
+ style: UIBarButtonItem.Style.plain,
target: webViewController,
action: #selector(SwiftWebVC.doneButtonTapped))
diff --git a/SwiftWebVC/SwiftWebVC.swift b/SwiftWebVC/SwiftWebVC.swift
index 584e273..195cacf 100755
--- a/SwiftWebVC/SwiftWebVC.swift
+++ b/SwiftWebVC/SwiftWebVC.swift
@@ -23,7 +23,7 @@ public class SwiftWebVC: UIViewController {
lazy var backBarButtonItem: UIBarButtonItem = {
var tempBackBarButtonItem = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: "SwiftWebVCBack"),
- style: UIBarButtonItemStyle.plain,
+ style: UIBarButtonItem.Style.plain,
target: self,
action: #selector(SwiftWebVC.goBackTapped(_:)))
tempBackBarButtonItem.width = 18.0
@@ -33,7 +33,7 @@ public class SwiftWebVC: UIViewController {
lazy var forwardBarButtonItem: UIBarButtonItem = {
var tempForwardBarButtonItem = UIBarButtonItem(image: SwiftWebVC.bundledImage(named: "SwiftWebVCNext"),
- style: UIBarButtonItemStyle.plain,
+ style: UIBarButtonItem.Style.plain,
target: self,
action: #selector(SwiftWebVC.goForwardTapped(_:)))
tempForwardBarButtonItem.width = 18.0
@@ -42,7 +42,7 @@ public class SwiftWebVC: UIViewController {
}()
lazy var refreshBarButtonItem: UIBarButtonItem = {
- var tempRefreshBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.refresh,
+ var tempRefreshBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.refresh,
target: self,
action: #selector(SwiftWebVC.reloadTapped(_:)))
tempRefreshBarButtonItem.tintColor = self.buttonColor
@@ -50,7 +50,7 @@ public class SwiftWebVC: UIViewController {
}()
lazy var stopBarButtonItem: UIBarButtonItem = {
- var tempStopBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.stop,
+ var tempStopBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.stop,
target: self,
action: #selector(SwiftWebVC.stopTapped(_:)))
tempStopBarButtonItem.tintColor = self.buttonColor
@@ -58,7 +58,7 @@ public class SwiftWebVC: UIViewController {
}()
lazy var actionBarButtonItem: UIBarButtonItem = {
- var tempActionBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action,
+ var tempActionBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.action,
target: self,
action: #selector(SwiftWebVC.actionButtonTapped(_:)))
tempActionBarButtonItem.tintColor = self.buttonColor
@@ -68,17 +68,20 @@ public class SwiftWebVC: UIViewController {
lazy var webView: WKWebView = {
var tempWebView = WKWebView(frame: UIScreen.main.bounds)
- tempWebView.uiDelegate = self
tempWebView.navigationDelegate = self
return tempWebView;
}()
var request: URLRequest!
- var navBarTitle: UILabel!
+ var navBarTitle: UILabel?
+
+ var navBarTextField: UITextField?
var sharingEnabled = true
+ var showAddressBar: Bool = true
+
////////////////////////////////////////////////
deinit {
@@ -88,21 +91,32 @@ public class SwiftWebVC: UIViewController {
webView.navigationDelegate = nil;
}
- public convenience init(urlString: String, sharingEnabled: Bool = true) {
+ public convenience init(urlString: String,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
var urlString = urlString
if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") {
urlString = "https://"+urlString
}
- self.init(pageURL: URL(string: urlString)!, sharingEnabled: sharingEnabled)
+ self.init(pageURL: URL(string: urlString)!,
+ sharingEnabled: sharingEnabled,
+ showAddressBar: showAddressBar)
}
- public convenience init(pageURL: URL, sharingEnabled: Bool = true) {
- self.init(aRequest: URLRequest(url: pageURL), sharingEnabled: sharingEnabled)
+ public convenience init(pageURL: URL,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
+ self.init(aRequest: URLRequest(url: pageURL),
+ sharingEnabled: sharingEnabled,
+ showAddressBar: showAddressBar)
}
- public convenience init(aRequest: URLRequest, sharingEnabled: Bool = true) {
+ public convenience init(aRequest: URLRequest,
+ sharingEnabled: Bool = true,
+ showAddressBar: Bool = true) {
self.init()
self.sharingEnabled = sharingEnabled
+ self.showAddressBar = showAddressBar
self.request = aRequest
}
@@ -126,27 +140,43 @@ public class SwiftWebVC: UIViewController {
assert(self.navigationController != nil, "SVWebViewController needs to be contained in a UINavigationController. If you are presenting SVWebViewController modally, use SVModalWebViewController instead.")
updateToolbarItems()
- navBarTitle = UILabel()
- navBarTitle.backgroundColor = UIColor.clear
- if presentingViewController == nil {
- if let titleAttributes = navigationController!.navigationBar.titleTextAttributes {
- navBarTitle.textColor = titleAttributes[.foregroundColor] as? UIColor
+
+ if showAddressBar {
+ let textField = UITextField()
+ textField.keyboardType = .URL
+ textField.text = request.url?.absoluteString
+ textField.borderStyle = .roundedRect
+ textField.clearButtonMode = .whileEditing
+ textField.returnKeyType = .go
+ textField.delegate = self
+ textField.enablesReturnKeyAutomatically = true
+ textField.autocapitalizationType = .none
+ textField.frame.size.width = 400
+ navigationItem.titleView = textField
+ self.navBarTextField = textField
+ } else {
+ let navBarTitle = UILabel()
+ navBarTitle.backgroundColor = UIColor.clear
+ if presentingViewController == nil {
+ if let titleAttributes = navigationController!.navigationBar.titleTextAttributes {
+ navBarTitle.textColor = titleAttributes[.foregroundColor] as? UIColor
+ }
}
+ else {
+ navBarTitle.textColor = self.titleColor
+ }
+ navBarTitle.shadowOffset = CGSize(width: 0, height: 1);
+ navBarTitle.font = UIFont(name: "HelveticaNeue-Medium", size: 17.0)
+ navBarTitle.textAlignment = .center
+ navigationItem.titleView = navBarTitle
+ self.navBarTitle = navBarTitle
}
- else {
- navBarTitle.textColor = self.titleColor
- }
- navBarTitle.shadowOffset = CGSize(width: 0, height: 1);
- navBarTitle.font = UIFont(name: "HelveticaNeue-Medium", size: 17.0)
- navBarTitle.textAlignment = .center
- navigationItem.titleView = navBarTitle;
super.viewWillAppear(true)
if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone) {
self.navigationController?.setToolbarHidden(false, animated: false)
- }
- else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
+ } else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
self.navigationController?.setToolbarHidden(true, animated: true)
}
}
@@ -173,8 +203,8 @@ public class SwiftWebVC: UIViewController {
let refreshStopBarButtonItem: UIBarButtonItem = webView.isLoading ? stopBarButtonItem : refreshBarButtonItem
- let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
- let flexibleSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
+ let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.fixedSpace, target: nil, action: nil)
+ let flexibleSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
@@ -280,10 +310,32 @@ public class SwiftWebVC: UIViewController {
}
-extension SwiftWebVC: WKUIDelegate {
-
- // Add any desired WKUIDelegate methods here: https://developer.apple.com/reference/webkit/wkuidelegate
+extension SwiftWebVC: UITextFieldDelegate {
+ public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
+
+ textField.endEditing(true)
+
+ guard let text = textField.text else {
+ return false
+ }
+
+ guard let url = URL(string: text) else {
+ return false
+ }
+
+ let request = URLRequest(url: url)
+
+ loadRequest(request)
+
+ return true
+ }
+ public func textFieldShouldClear(_ textField: UITextField) -> Bool {
+
+ textField.text = "https://"
+
+ return false
+ }
}
extension SwiftWebVC: WKNavigationDelegate {
@@ -298,9 +350,17 @@ extension SwiftWebVC: WKNavigationDelegate {
self.delegate?.didFinishLoading(success: true)
UIApplication.shared.isNetworkActivityIndicatorVisible = false
+ if let navBarTextField = self.navBarTextField {
+ navBarTextField.text = webView.url?.absoluteString
+ }
+
webView.evaluateJavaScript("document.title", completionHandler: {(response, error) in
- self.navBarTitle.text = response as! String?
- self.navBarTitle.sizeToFit()
+
+ if let navBarTitle = self.navBarTitle {
+ navBarTitle.text = response as! String?
+ navBarTitle.sizeToFit()
+ }
+
self.updateToolbarItems()
})
@@ -319,15 +379,15 @@ extension SwiftWebVC: WKNavigationDelegate {
let hostAddress = navigationAction.request.url?.host
if (navigationAction.targetFrame == nil) {
- if UIApplication.shared.canOpenURL(url!) {
- UIApplication.shared.openURL(url!)
+ if let url = url, UIApplication.shared.canOpenURL(url) {
+ UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
// To connnect app store
if hostAddress == "itunes.apple.com" {
- if UIApplication.shared.canOpenURL(navigationAction.request.url!) {
- UIApplication.shared.openURL(navigationAction.request.url!)
+ if let url = navigationAction.request.url, UIApplication.shared.canOpenURL(url) {
+ UIApplication.shared.open(url, options: [:], completionHandler: nil)
decisionHandler(.cancel)
return
}
@@ -362,7 +422,7 @@ extension SwiftWebVC: WKNavigationDelegate {
if let requestUrl: URL = URL(string:"\(urlScheme)"+"\(additional_info)") {
let application:UIApplication = UIApplication.shared
if application.canOpenURL(requestUrl) {
- application.openURL(requestUrl)
+ application.open(requestUrl, options: [:], completionHandler: nil)
}
}
}
diff --git a/SwiftWebVC/SwiftWebVCActivity.swift b/SwiftWebVC/SwiftWebVCActivity.swift
index a73bd11..504961d 100755
--- a/SwiftWebVC/SwiftWebVCActivity.swift
+++ b/SwiftWebVC/SwiftWebVCActivity.swift
@@ -11,13 +11,14 @@ import UIKit
class SwiftWebVCActivity: UIActivity {
- var URLToOpen: URL?
+ var urlToOpen: URL?
+
var schemePrefix: String?
- override var activityType : UIActivityType? {
+ override var activityType : UIActivity.ActivityType? {
let typeArray = "\(type(of: self))".components(separatedBy: ".")
let _type: String = typeArray[typeArray.count-1]
- return UIActivityType(rawValue: _type)
+ return UIActivity.ActivityType(rawValue: _type)
}
override var activityImage : UIImage {
@@ -33,7 +34,7 @@ class SwiftWebVCActivity: UIActivity {
override func prepare(withActivityItems activityItems: [Any]) {
for activityItem in activityItems {
if activityItem is URL {
- URLToOpen = activityItem as? URL
+ urlToOpen = activityItem as? URL
}
}
}
diff --git a/SwiftWebVC/SwiftWebVCActivityChrome.swift b/SwiftWebVC/SwiftWebVCActivityChrome.swift
index aee26ba..3bae482 100755
--- a/SwiftWebVC/SwiftWebVCActivityChrome.swift
+++ b/SwiftWebVC/SwiftWebVCActivityChrome.swift
@@ -24,28 +24,25 @@ class SwiftWebVCActivityChrome : SwiftWebVCActivity {
}
override func perform() {
- let inputURL: URL! = URLToOpen as URL!
- let scheme: String! = inputURL.scheme
- // Replace the URL Scheme with the Chrome equivalent.
- var chromeScheme: String? = nil;
- if scheme == "http" {
- chromeScheme = "googlechrome"
+ guard let url = urlToOpen else {
+ return
}
- else if scheme == "https" {
- chromeScheme = "googlechromes"
+
+ var urlString = url.absoluteString
+
+ let httpScheme = "http"
+
+ if urlString.hasPrefix(httpScheme) {
+ urlString = String(urlString.dropFirst(httpScheme.count))
+ }
+
+ guard let currentUrl = URL(string: urlString) else {
+ return
}
- // Proceed only if a valid Google Chrome URI Scheme is available.
- if chromeScheme != nil {
- let absoluteString: NSString! = inputURL!.absoluteString as NSString!
- let rangeForScheme: NSRange! = absoluteString.range(of: ":")
- let urlNoScheme: String! = absoluteString.substring(from: rangeForScheme.location)
- let chromeURLString: String! = chromeScheme!+urlNoScheme
- let chromeURL: URL! = URL(string: chromeURLString)
-
- // Open the URL with Chrome.
- UIApplication.shared.openURL(chromeURL)
+ if UIApplication.shared.canOpenURL(currentUrl) {
+ UIApplication.shared.open(currentUrl, options: [:], completionHandler: nil)
}
}
diff --git a/SwiftWebVC/SwiftWebVCActivitySafari.swift b/SwiftWebVC/SwiftWebVCActivitySafari.swift
index 20f824b..a25e98a 100755
--- a/SwiftWebVC/SwiftWebVCActivitySafari.swift
+++ b/SwiftWebVC/SwiftWebVCActivitySafari.swift
@@ -24,8 +24,16 @@ class SwiftWebVCActivitySafari : SwiftWebVCActivity {
}
override func perform() {
- let completed: Bool = UIApplication.shared.openURL(URLToOpen! as URL)
- activityDidFinish(completed)
+
+ guard let url = urlToOpen else {
+ return
+ }
+
+ if UIApplication.shared.canOpenURL(url) {
+ UIApplication.shared.open(url, options: [:]) { completed in
+ self.activityDidFinish(completed)
+ }
+ }
}
}