Come on in for part 9 of my “Making Apple TV Apps” series! Are you ready to forge new ground in app development? Today, we open our minds to creating apps with the new TVJS and TVML frameworks.
Choosing Your Approach(es)
As I said in a previous article, you can take the same approach to creating apps for the Apple TV as you’re used to with iOS. Xcode, storyboards, view controllers, etc., along with your language of choice, either Objective-C, Swift, or a mixture of both, are a perfectly viable approach. However, Apple has also introduced a new approach to app development with the new Apple TV.
Apple refers to this new approach as client/server apps, with client-side logic created using JavaScript (TVJS) and the user interface defined with TVML (XML-based) user interface templates. This approach works really well for content consumption apps because most of the TVML user interface templates are designed for the needs of those types of apps.
TVML UI Template Samples
Another benefit of this approach is the ability to change the presentation of content in your app without having to submit updates and going through the approval process. Making changes to your user interface and the content it is presenting is now as easy as modifying the XML data being delivered to your app.
By Our (App) Powers Combined!
Of course, like any technology, this new approach isn’t perfect. It doesn’t make all the frameworks offered by tvOS instantly available to JavaScript. You may also need to present something in a way that none of the Apple-provided UI templates provide out of the box.
Fortunately, TVML-based apps’ capabilities can easily be extended in these situations. You can define individual views or entire screens in Swift or Objective-C and make them accessible as custom tags in your TVML data. You can also expose functionality in both directions between your JavaScript and Objective-C or Swift native code. We’ll see how that is done in a future article in this series.
Server == Internet?
Before I wrap up today’s article, I want to point out one more thing about the JavaScript and XML-based approach. Although Apple refers to this approach as building client/server apps, there aren’t any hard rules that require the server that your app depends on to be a separate entity sitting out on the internet. For example, the needed script, data and image assets could be embedded in your app and served to Javascript from native code. This may mean all the resources are static files, or that you’ve written code on the native side to fetch a web service response with a non-TVML payload, or even query results from CloudKit, before calling a method on the Javascript side of your app to deliver the TVML-formatted results. There are a lot of possibilities when it comes to how you provide the content your JavaScript-based app depends on.
Closing Time
We’re just getting started with our look at this new approach for creating Apple TV apps. In my next article, we’ll walk through the step-by-step process of creating and successfully launching our first TVJS/TVML based app. I hope you’ll join me for that! Thanks as always for stopping by.
Leave a Reply