0

I am able to implement the new WebKit in 7.1 Deployment. I can use it without error on the devices running in iOS8 up. However, when the device falls below iOS8, my WKWebView becomes nil even after the initialization, my suspect was even if you silence webkit and successfully add it on your project and the deployment was 7.1, if the OS actually fall below iOS8 this WebKit becomes unvalable.

I want to confirm this error so I can proceed. Since this webkit was introduced as of the release of swift and iOS8. Thanks

eNeF
  • 3,241
  • 2
  • 18
  • 41

1 Answers1

0

Here is a simple example, where I create a new protocol and extend both UIWebView and WKWebView from the same protocol. With this, it makes a easy to keep track of both these views inside my view controller and both of these use common method to load from url, it makes easy for abstraction.

protocol MyWebView{
  func loadRequestFromUrl(url: NSURL!)
}

extension UIWebView:MyWebView{
  func loadRequestFromUrl(url: NSURL!){
    let urlRequest = NSURLRequest(URL: url)
    loadRequest(urlRequest)
  }
}

extension WKWebView:MyWebView{
  func loadRequestFromUrl(url: NSURL!){
    let urlRequest = NSURLRequest(URL: url)
    loadRequest(urlRequest)
  }
}

 // This is a simple closure, which takes the compared system version, the comparison test success block and failure block 

let SYSTEM_VERSION_GREATER_THAN_OR_EQUAL: (String, () -> (), () -> ()) -> Void = {
  (var passedVersion: String, onTestPass: () -> (), onTestFail: () -> ()) in
  let device = UIDevice.currentDevice()
  let version = device.systemVersion
  let comparisonOptions = version.compare(passedVersion, options: NSStringCompareOptions.NumericSearch, range: Range(start: version.startIndex, end: version.endIndex), locale: nil)
   if comparisonOptions == NSComparisonResult.OrderedAscending || comparisonOptions == NSComparisonResult.OrderedSame{
    onTestPass()
   }else{
    onTestFail()
  }

}
class ViewController: UIViewController{

  var webView: MyWebView!

  override func viewDidLoad() {

    super.viewDidLoad()

    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL("8.0",
    {
      let  theWebView = WKWebView(frame: self.view.bounds)
      self.view.addSubview(theWebView)
      self.webView = theWebView
    },
      {
      let theWebView = UIWebView(frame: self.view.bounds)
      self.view.addSubview(theWebView)
      self.webView = theWebView

    })

    webView.loadRequestFromUrl(NSURL(string: "http://google.com"))

  }

}
Sandeep
  • 20,908
  • 7
  • 66
  • 106
  • I have done that alread, thanks for posting.. that means adding WebKit framework only does silent the warnings and errors. – eNeF Oct 13 '14 at 08:39