Apple has released it's SDK for apple tv yesterday.
Most apps for TVs are web based (html, javascript and css) and I would like to port an existing tv web app to the tvOS.
The SDK in Xcode shows no Webview implementation like in iOS for creating apps based in html, javascript and css, however, according to the docs, it is possible to use javascript using tvjs framework, but instead of html, apple has it's own markup language for TVs called TVML.
My question is: Is it possible to port an existing web app to tvOS (how?), or does it need to be reimplemented from scratch?
Thanks for your help.
No. There is no web browser for Apple TV. You can use Airplay too mirror a web browser from an iOS device or Mac though.
Swipe up on Control Panel and choose Screen Mirroring. Choose your Apple TV. Now you should see a browser on the TV screen and a url bar on the iPhone. Tap on the URL bar and enter the name of the site you wish to visit, or a search phrase.
However, when it comes to web browsing functionality, it's pretty limited. Despite being one of the best TV streaming services (opens in new tab), Apple removed Safari support after the 3rd generation of Apple TV meaning you can't install a web browser on the latest Apple TVs.
EDIT: Before people keeps downvoting, I'm going to make clear that the UIWebView is present on the apple TV, but it's PROHIBITED to use it, so, the only real way of loading web apps on an apple TV is creating them with TVML and TVJS
If you want to use an UIWebView (as proof of concept) you can do this:
Objective-c
Class webviewClass = NSClassFromString(@"UIWebView"); id webview = [[webviewClass alloc] initWithFrame:self.view.frame]; NSURL * url = [NSURL URLWithString:@"https://www.google.com"]; NSURLRequest * request = [NSURLRequest requestWithURL:url]; [webview loadRequest:request]; [self.view addSubview:webview];
swift
let webViewClass : AnyObject.Type = NSClassFromString("UIWebView")! let webViewObject : NSObject.Type = webViewClass as! NSObject.Type let webview: AnyObject = webViewObject.init() let url = NSURL(string: "https://www.google.com") let request = NSURLRequest(URL: url!) webview.loadRequest(request) let uiview = webview as! UIView uiview.frame = CGRectMake(0, 0, view.frame.width, view.frame.height) view.addSubview(uiview)
MAGIC!!! The UIWebView
is there! But you can't iteract with it, just show web pages or web content.
UPDATE! I've found that there is a lot of tvOS browsers on github based on https://github.com/steventroughtonsmith/tvOSBrowser, but most of them require tweaking Availability.h on Xcode app. I've found a fork that uses my approach, so it doesn't require tweaking Availability.h https://github.com/FabioSpacagna/tvOSBrowser They add basic support for navigating, like scroll and a cursor
I don't think apple will approve apps using UIWebView
as it's marked as prohibited, you'll have to learn TVML
and TVJS
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With