更新xcode 6到7(代码不能快速工作)

时间:2015-10-22 14:55:11

标签: xcode swift webview updates

我有一个项目快速与一些webView(我使用WKWebView),它没有任何问题。 我将我的xcode更新为7.1版本,现在我的webview工作都没有。我没有错误,但我的屏幕上没有任何内容。如果有人有一个想法谢谢

(对不起我的英文)

 class Actu: UIViewController, WKNavigationDelegate  {

/**** Variable declaration and IBoutlet *****/

    @IBOutlet weak var contact: UIBarButtonItem!
    var BackButtonItem:UIBarButtonItem!
    var rightplayBarButtonItem:UIBarButtonItem!
    var refreshPageButton:UIBarButtonItem!
    var webView: WKWebView
    var varIntermediate = String()
    let urlContainer = StreamPlayer.sharedInstance.url

/**** Javascript Insertion *****/

required init?(coder aDecoder: NSCoder){
    let config = WKWebViewConfiguration()
    let scriptURL = NSBundle.mainBundle().pathForResource("hideSectionsActu", ofType: "js")
    let scriptContent = try? String(contentsOfFile:scriptURL!, encoding:NSUTF8StringEncoding)
    let script = WKUserScript(source: scriptContent!, injectionTime: .AtDocumentStart, forMainFrameOnly: true)
    config.userContentController.addUserScript(script)
    self.webView = WKWebView(frame: CGRectZero, configuration: config)
    super.init(coder: aDecoder)
    self.webView.navigationDelegate = self
}
   ////////////////////////////////////////////////
   /**** View did Load *****/

override func viewDidLoad() {
    super.viewDidLoad()

    self.BackButtonItem = UIBarButtonItem(title: "Retour", style: UIBarButtonItemStyle.Plain, target: self, action: "back:")
    self.refreshPageButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Refresh, target: self, action: "refresh:")

    // Webview creation//
    webView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(webView)
    webView.translatesAutoresizingMaskIntoConstraints = false
    let height = NSLayoutConstraint(item: webView, attribute: .Height, relatedBy: .Equal, toItem: view, attribute: .Height, multiplier: 1, constant: 0)
    let width = NSLayoutConstraint(item: webView, attribute: .Width, relatedBy: .Equal, toItem: view, attribute: .Width, multiplier: 1, constant: 0)
    view.addConstraints([height, width])

    webView.addObserver(self, forKeyPath: "loading", options: .New, context: nil)

    let url = NSURL(string: "MyURL")
    let request = NSURLRequest(URL: url!)
    webView.loadRequest(request)

}
///////////////////////////////////////////
func webViewFunction(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {

}

func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {

    let javaScriptString : NSString = "var el=document.getElementsByClassName(\"home-link\")[0];el.removeAttribute(\"href\");"

    webView.evaluateJavaScript(javaScriptString as String, completionHandler: nil)
}

这是我的代码"转换"来自xcode 7

1 个答案:

答案 0 :(得分:1)

您应该注意以下2个提示:

1.请注意此设置:

PROJECT/TARGETS -> Build Settings -> Build Options -> Embedded Content Contains Swift Code -> YES

2.在你的plist文件中,你应该添加:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

如果您使用Xcode 7或更高版本重建项目,则可以请求非https互联网请求。