Xcode 6.1升级 - ViewController不再符合协议WKScriptMessageHandler

时间:2014-10-22 12:55:49

标签: ios xcode swift webkit

我在iOS应用中使用WKScriptMessageHandler来接收来自Webkit的消息。我使用WKScriptMessageHandler协议,但显然在将Xcode升级到最新的6.1升级之后,我现在收到此错误消息:

Type 'ViewController' does not conform to protocol 'WKScriptMessageHandler'

关于如何做到这一点的任何想法?为什么Apple会改变这个

以下是我的代码:

import UIKit
import WebKit

class ViewController: UIViewController, WKScriptMessageHandler {

    @IBAction func fourButton(sender: UIButton){
        performSegueWithIdentifier("login", sender: self)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func userContentController(userContentController: WKUserContentController!, didReceiveScriptMessage message: WKScriptMessage!){
        println("got message: \(message.body)")
    }

}

1 个答案:

答案 0 :(得分:6)

功能定义已更改,请删除感叹号:

func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage)