Does WatchKit support html? is there is controller like UIWebview ?.
My client want to show webpage in a Apple Watch. is this possible ?
Seems like WatchOS5 has added limited support for WebKit:
No. There isn't anything like UIWebView
in WatchKit.
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) ")
}
}
}
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.