4

I'm building a sort of webshop for Apple TV with tvOS, which I'm very new at!

I was wondering, can you write you're own template in xml or are you stuck with the default templates apple is providing? Maybe it is possible for combining different templates in each other?

Steaphann
  • 2,797
  • 6
  • 50
  • 109
  • 1
    Perhaps the divTemplate? https://developer.apple.com/library/tvos/documentation/LanguagesUtilities/Conceptual/ATV_Template_Guide/DivTemplate.html#//apple_ref/doc/uid/TP40015064-CH28-SW1 – Frank C. Dec 30 '15 at 00:27

1 Answers1

1

Sort of. You can write your own templates, but it involves a few different parts. Also, I don't know of a way for custom written templates to interact with the NavigationDocument. So, you're limited to either:

  1. All Apple templates
  2. All custom templates
  3. Apple templates with some custom leaf templates.

By (3) I mean that you use Apple templates to drive the majority of your pages, but they the last pages you push are full screen modal views that simply cover up the NavigationDocument template stack.

Assuming you'd like to try (2) or (3), read on.

Native Part

First, you need the native part. This is either Objective-C or Swift code that you use to build UIKit based classes that can display your custom UI and handle events.

The native part uses JavaScriptCore to expose itself to the JavaScript runtime in the TVApplicationControllerDelegate's -[appController:evaluateAppJavaScriptInContext:] method.

I'd recommend Objective-C for this because the syntax required to work with JavaScriptCore is simpler.

Template Processing Part

This can be either JavaScript or native. It reads your JSON or XML data, creates the native objects via the interfaces you previously exposed, and then map the JSON/XML values into the properties on your native objects. Finally, you need to present the view to the screen, either covering up the NavigationDocument template stack or by using your own custom navigation stack.

Doug Richardson
  • 10,483
  • 6
  • 51
  • 77