Does WatchKit support html? is there is controller like UIWebview?

流过昼夜 提交于 2019-12-01 00:50:08

There's no UIWebView in WatchKit (neither WatchOS 1 nor WatchOS 2).

However, it's fully possible to work around this:

You can load the HTML, pick out the relevant content, and display that in for example a Label. This is however not a smart solution, as the website owners can change its layout and render your app useless until you update it.

My suggestion is to send a GET-request to the server and receive the relevant data in JSON-format if they have an API. If they don't, you can use a service such as Kimono to convert the website into an API.

Or you could set up your own server which works as the API. You simply send a request to it, it queries the website/ loads the HTML, and returns the relevant content to your app.

In any case, the solution is to get the relevant content from the website and display that using labels and image views.

There is no webView in watchKit ,But i managed to convert HTML to formatted String

func convertHTMLToFormattedText ( htmlText : String , myLabel : WKInterfaceLabel) {

    let attributeText: NSAttributedString?

    if let htmlData = htmlText.dataUsingEncoding(NSUnicodeStringEncoding) {

        do {

            attributeText  =  try   NSAttributedString(data: htmlData , options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            myLabel.setAttributedText(attributeText)

        }catch let e as NSError {
            print("Couldn't translate \(htmlText): \(e.localizedDescription) ")
        }


    }
}

No. There isn't anything like UIWebView in WatchKit.

Seems like WatchOS5 has added limited support for WebKit:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!