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

我是研究僧i 提交于 2019-12-09 01:08:58

问题


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

My client want to show webpage in a Apple Watch. is this possible ?


回答1:


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.




回答2:


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) ")
        }


    }
}



回答3:


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




回答4:


Seems like WatchOS5 has added limited support for WebKit:

  • How to use WebKit on watchOS 5?
  • https://developer.apple.com/videos/play/wwdc2018/239


来源:https://stackoverflow.com/questions/30839510/does-watchkit-support-html-is-there-is-controller-like-uiwebview

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