From c316c4791f938e263a24af3eab9b8d42c187ceba Mon Sep 17 00:00:00 2001 From: wyy Date: Mon, 23 Sep 2019 10:29:13 +0800 Subject: [PATCH] migrating to swift 5.0 --- example/ios/Runner.xcodeproj/project.pbxproj | 7 ++++--- example/ios/Runner/AppDelegate.swift | 2 +- .../InAppBrowserWebViewController.swift | 14 +++++++------- ios/Classes/InAppWebView.swift | 2 +- ios/Classes/SafariViewController.swift | 2 +- ios/Classes/SwiftFlutterPlugin.swift | 19 ++++++++++++------- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 42d70d556..b380bdf5d 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -179,7 +179,7 @@ 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = PFP8UV45Y6; - LastSwiftMigration = 0910; + LastSwiftMigration = 1100; }; }; }; @@ -188,6 +188,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -447,7 +448,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -475,7 +476,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift index 71cc41e34..70693e4a8 100644 --- a/example/ios/Runner/AppDelegate.swift +++ b/example/ios/Runner/AppDelegate.swift @@ -5,7 +5,7 @@ import Flutter @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) diff --git a/ios/Classes/InAppBrowserWebViewController.swift b/ios/Classes/InAppBrowserWebViewController.swift index a9f187267..a110ef889 100644 --- a/ios/Classes/InAppBrowserWebViewController.swift +++ b/ios/Classes/InAppBrowserWebViewController.swift @@ -172,8 +172,8 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU } func prepareConstraints () { - containerWebView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.containerWebView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0) - containerWebView_TopFullScreenConstraint = NSLayoutConstraint(item: self.containerWebView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0) + containerWebView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.containerWebView, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 0) + containerWebView_TopFullScreenConstraint = NSLayoutConstraint(item: self.containerWebView, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.view, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 0) webView.translatesAutoresizingMaskIntoConstraints = false let height = NSLayoutConstraint(item: webView, attribute: .height, relatedBy: .equal, toItem: containerWebView, attribute: .height, multiplier: 1, constant: 0) @@ -183,8 +183,8 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU let bottomContraint = NSLayoutConstraint(item: webView, attribute: .bottomMargin, relatedBy: .equal, toItem: containerWebView, attribute: .bottomMargin, multiplier: 1, constant: 0) containerWebView.addConstraints([height, width, leftConstraint, rightConstraint, bottomContraint]) - webView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.containerWebView, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0) - webView_TopFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self.containerWebView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0) + webView_BottomFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.containerWebView, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 0) + webView_TopFullScreenConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.containerWebView, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 0) } func prepareWebView() { @@ -254,7 +254,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU } func setWebViewFrame(_ frame: CGRect) { - print("Setting the WebView's frame to \(NSStringFromCGRect(frame))") + print("Setting the WebView's frame to \(NSCoder.string(for: frame))") webView.frame = frame } @@ -276,7 +276,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU DispatchQueue.main.async(execute: {() -> Void in if (weakSelf?.responds(to: #selector(getter: self.presentingViewController)))! { weakSelf?.presentingViewController?.dismiss(animated: true, completion: {() -> Void in - self.tmpWindow?.windowLevel = 0.0 + self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0) UIApplication.shared.delegate?.window??.makeKeyAndVisible() if (self.navigationDelegate != nil) { self.navigationDelegate?.browserExit(uuid: self.uuid) @@ -285,7 +285,7 @@ class InAppBrowserWebViewController: UIViewController, UIScrollViewDelegate, WKU } else { weakSelf?.parent?.dismiss(animated: true, completion: {() -> Void in - self.tmpWindow?.windowLevel = 0.0 + self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0) UIApplication.shared.delegate?.window??.makeKeyAndVisible() if (self.navigationDelegate != nil) { self.navigationDelegate?.browserExit(uuid: self.uuid) diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift index ee27192e8..8f6dd4afe 100644 --- a/ios/Classes/InAppWebView.swift +++ b/ios/Classes/InAppWebView.swift @@ -240,7 +240,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi takeSnapshot(with: nil, completionHandler: {(image, error) -> Void in var imageData: Data? = nil if let screenshot = image { - imageData = UIImagePNGRepresentation(screenshot)! + imageData = screenshot.pngData()! } completionHandler(imageData) }) diff --git a/ios/Classes/SafariViewController.swift b/ios/Classes/SafariViewController.swift index b4fc5b942..4abe0db65 100644 --- a/ios/Classes/SafariViewController.swift +++ b/ios/Classes/SafariViewController.swift @@ -43,7 +43,7 @@ class SafariViewController: SFSafariViewController, SFSafariViewControllerDelega dismiss(animated: true) DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(400), execute: {() -> Void in - self.tmpWindow?.windowLevel = 0.0 + self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0) UIApplication.shared.delegate?.window??.makeKeyAndVisible() if (self.statusDelegate != nil) { diff --git a/ios/Classes/SwiftFlutterPlugin.swift b/ios/Classes/SwiftFlutterPlugin.swift index e2f9a80b3..2b40bca8d 100644 --- a/ios/Classes/SwiftFlutterPlugin.swift +++ b/ios/Classes/SwiftFlutterPlugin.swift @@ -350,7 +350,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { let tmpController = UIViewController() let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel self.tmpWindow?.rootViewController = tmpController - self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1) + self.tmpWindow?.windowLevel = UIWindow.Level(baseWindowLevel!.rawValue + 1) self.tmpWindow?.makeKeyAndVisible() let browserOptions: InAppBrowserOptions @@ -435,7 +435,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { // UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)! // } webViewController.presentingViewController?.dismiss(animated: false, completion: {() -> Void in - self.tmpWindow?.windowLevel = 0.0 + self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0) UIApplication.shared.delegate?.window??.makeKeyAndVisible() }) } @@ -466,7 +466,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { let tmpController = UIViewController() let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel self.tmpWindow?.rootViewController = tmpController - self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1) + self.tmpWindow?.windowLevel = UIWindow.Level(baseWindowLevel!.rawValue + 1) self.tmpWindow?.makeKeyAndVisible() let browserOptions: InAppBrowserOptions @@ -499,7 +499,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { webViewController.webView.loadData(data: data, mimeType: mimeType, encoding: encoding, baseUrl: baseUrl) }) webViewController.presentingViewController?.dismiss(animated: false, completion: {() -> Void in - self.tmpWindow?.windowLevel = 0.0 + self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0) UIApplication.shared.delegate?.window??.makeKeyAndVisible() }) } @@ -518,7 +518,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { } else { if #available(iOS 10.0, *) { - UIApplication.shared.open(url, options: [:], completionHandler: nil) + UIApplication.shared.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil) } else { UIApplication.shared.openURL(url) } @@ -536,7 +536,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { DispatchQueue.main.async(execute: {() -> Void in if webViewController != nil { let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel - self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1) + self.tmpWindow?.windowLevel = UIWindow.Level(baseWindowLevel!.rawValue + 1) self.tmpWindow?.makeKeyAndVisible() UIApplication.shared.delegate?.window??.makeKeyAndVisible() self.tmpWindow?.rootViewController?.present(webViewController!, animated: true, completion: nil) @@ -558,7 +558,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { DispatchQueue.main.async(execute: {() -> Void in if webViewController != nil { webViewController?.presentingViewController?.dismiss(animated: true, completion: {() -> Void in - self.tmpWindow?.windowLevel = 0.0 + self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0) UIApplication.shared.delegate?.window??.makeKeyAndVisible() if self.previousStatusBarStyle != -1 { UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)! @@ -749,3 +749,8 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] { + return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)}) +}