WkWebView won't loadHTMLstring

前端 未结 2 685
误落风尘
误落风尘 2020-12-15 23:09

I\'m trying to show in a WkWebView an html page that I previously downloaded and stored in a String.

This is how I setup my WkWebView:

    webView =          


        
相关标签:
2条回答
  • 2020-12-15 23:19

    SWIFT

    You might be making it a bit too complicated. This worked for me ...

    First, import WebKit

    Second, create an @IBOutlet under your class:

    @IBOutlet weak var webView: WKWebView!
    

    Third, place the following in your viewDidLoad():

    let htmlString:String! = "\(YourString)"
    webView.loadHTMLString(htmlString, baseURL: NSBundle.mainBundle().bundleURL)
    

    SWIFT 3 update

    webView.loadHTMLString(htmlString, baseURL: Bundle.main.bundleURL)
    
    0 讨论(0)
  • 2020-12-15 23:30

    I met the same problem as you! The key problem is in the project settings:

    Check your Xcode Project > Target > Capabilities > App Sandbox.

    Make sure you've CHECKED the NetWork ✅ Incoming & ✅ Outgoing connections.

    See the SreenShot Below:

    0 讨论(0)
提交回复
热议问题