Close ad

Apple last week presented, among other things the new Apple TV with the tvOS operating system. The fact that applications from the App Store can be installed in the new black box certainly made the developers most happy.

Developers have two options. They can write a native app that has full access to the Apple TV hardware. The available SDK (set of libraries for developers) is very similar to what developers already know from the iPhone, iPad, and the programming languages ​​are the same - Objective-C and the younger Swift.

But for simpler applications, Apple offered developers a second option in the form of TVML - Television Markup Language. If you feel that the name TVML looks suspiciously like HTML, you're right. It is really a markup language based on XML and very similar to HTML, only it is much simpler and has a stricter syntax. But it is absolutely perfect for applications like Netflix. And users will benefit too, because the strictness of TVML will make multimedia applications look and work much the same.

Path to the first application

So the first thing I had to do was download the new beta version of the Xcode development environment (version 7.1 is available <a href="https://cdn.shopify.com/s/files/1/1932/8043/files/200721_ODSTOUPENI_BEZ_UDANI_DUVODU__EN.pdf?v=1595428404" data-gt-href-en="https://en.notsofunnyany.com/">here</a>). This gave me access to the tvOS SDK and was able to start a new project specifically targeting the fourth generation Apple TV. The app can be tvOS-only, or the code can be added to an existing iOS app to create a “universal” app – a model similar to iPhone and iPad apps today.

Problem one: Xcode only offers the ability to create a native app. But I very quickly found a section in the documentation that will help developers change this skeleton and prepare it for TVML. Basically, it's a few lines of code in Swift that, just on the Apple TV, create a full-screen object and load the main part of the app, which is already written in JavaScript.

Problem two: TVML applications are really very similar to a web page, and therefore all the code is also loaded from the Internet. The application itself is actually just a "bootloader", it contains only a minimum of code and the most basic graphic elements (application icon and the like). In the end, I successfully put the main JavaScript code directly into the app and got the ability to at least display a custom error message when the Apple TV is not connected to the Internet.

The third small problem: iOS 9 and with it tvOS strictly requires that all communication towards the Internet takes place encrypted via HTTPS. This is a feature introduced in iOS 9 for all apps and the reason is pressure on user privacy and data security. So it will be necessary to deploy an SSL certificate on the web server. It can be purchased for as little as $5 (120 crowns) per year, or you can use, for example, the CloudFlare service, which will take care of HTTPS by itself, automatically and without investment. The second option is to turn off this restriction for the application, which is possible for now, but I would definitely not recommend it.

After a few hours of reading the documentation, where there are still occasional minor errors, I worked out a very basic but working application. It displayed the popular text "Hello World" and two buttons. I spent about two hours trying to get the button to be active and actually do something. But considering the early hours of the morning, I preferred to go to sleep… and that was a good thing.

The other day, I had the bright idea to download a ready-made sample TVML application directly from Apple. I found what I was looking for very quickly in the code and the button was live and working. Among other things, I also discovered the first two parts of the tvOS tutorial on the Internet. Both resources helped a lot, so I started a new project and started my first real application.

First real application

I started completely from scratch, the first TVML page. The advantage is that Apple has prepared 18 ready-made TVML templates for developers that just need to be copied from the documentation. Editing one template took about an hour, primarily because I was preparing our API to send the finished TVML with all the necessary data to the Apple TV.

The second template only took about 10 minutes. I've added two JavaScripts - most of the code in them comes directly from Apple, so why reinvent the wheel. Apple has prepared scripts that take care of loading and displaying TVML templates, including the recommended content loading indicator and possible error display.

In less than two hours, I was able to put together a very bare, but functioning PLAY.CZ application. It can display a list of radio stations, it can filter it by genre and it can start the radio. Yes, a lot of things are not in the app, but the basics work.

[youtube id=”kLKvWC-rj7Q” width=”620″ height=”360″]

The advantage is that the application is basically nothing more than a special version of the website, which is powered by JavaScript and you can also use CSS to modify the appearance.

Apple still requires a few more things to prepare. The application icon is not one, but two - smaller and larger. The novelty is that the icon is not a simple image, but contains a parallax effect and is composed of 2 to 5 layers (background, objects in the middle and foreground). All active images across the application can contain the same effect.

Each layer is actually just an image on a transparent background. Apple has prepared its own application for compiling these layered images and promises to release an export plugin for Adobe Photoshop soon.

Another requirement is a "Top Shelf" image. If the user places the app in a prominent position in the top row (on the top shelf), the app must also provide content for the desktop above the app list. There can be either just a simple picture or it can be an active area, for example with a list of favorite movies or, in our case, radio stations.

Many developers are just beginning to explore the possibilities of the new tvOS. The good news is that writing a content app is very easy, and Apple has gone a long way for developers with TVML. Building an application (for example PLAY.CZ or iVyszílő) should be easy and fast. There is a good chance that a large number of applications will be ready at the same time as the new Apple TV goes on sale.

Writing a native app or porting a game from iOS to tvOS will be more challenging, but not by much. The biggest hurdle will be different controls and a 200MB per app limit. A native application can only download a limited part of the data from the store, and everything else must be downloaded additionally, and there is no guarantee that the system will not delete this data. However, developers will certainly deal with this limitation quickly, also thanks to the availability of a set of tools called "App Thinning", which are also part of iOS 9.

.