The Hype to Swift 3.0 Tutorial Series is Finished!

Hmm.. I have not seen this issue and have used wkwebview in the past with no issues

I just did a convert on the project to use modernised swift syntax and update to modern Xcode.
Apart from Xcode throwing up some errors about some notifications syntax. Which can be ignored , just rerun build and they go away Xcode seems to jst want me to wast my time writing the line again.
All still works .

The whole swift file contains

//
//  ViewController.swift
//  iOSHypeCalls
//
//  Created by Mark Hunte on 18/09/2016.
//  Copyright © 2016 Mark Hunte. All rights reserved.
//

import UIKit
import WebKit
class ViewController: UIViewController {
    
    @IBOutlet var containerView : UIView! = nil
    
    var webView: WKWebView?
    
    override func loadView() {
        super.loadView()
        
     
        NotificationCenter.default.addObserver(self, selector: #selector(enterBackground), name: NSNotification.Name("UIApplicationWillResignActiveNotification"), object: nil)
       
      
        
        
 NotificationCenter.default.addObserver(self, selector: #selector(exitBackground), name:NSNotification.Name("UIApplicationWillEnterForegroundNotification"), object: nil)
        
 self.webView = WKWebView(frame: self.view.bounds)
        self.view = self.webView!
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let theUrl = Bundle.main.url(forResource: "testCall", withExtension:"html")
        let req = NSURLRequest(url: theUrl!)
        self.webView!.load(req as URLRequest)
    }

    func enterBackground()  {
        print("call 1")
        
         self.webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('splashScene', HYPE.documents['testCall'].kSceneTransitionCrossfade, 0.2);", completionHandler:nil )
       
    }
    
    
    
    
    func exitBackground()  {
        print("call 2")
   
        self.webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('scene1', HYPE.documents['testCall'].kSceneTransitionCrossfade, 3);", completionHandler:nil )
    }
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        
        
        
    }
    
    
}

And as you can see I do not have to massage the url !.

The one thing I notice is that I use NSURLRequest where you do not..
In mine I make sure I am using URLs and not strings.


 override func viewDidLoad() {
        super.viewDidLoad()
        let theUrl = Bundle.main.url(forResource: "testCall", withExtension:"html")
        let req = NSURLRequest(url: theUrl!)
        self.webView!.load(req as URLRequest)
    }
3 Likes