Skip to content

Instantly share code, notes, and snippets.

@thom4parisot
Last active January 27, 2016 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thom4parisot/e3c63a0fea1de8ea0106 to your computer and use it in GitHub Desktop.
Save thom4parisot/e3c63a0fea1de8ea0106 to your computer and use it in GitHub Desktop.
Apple TV - Sample App

Running the NativeScript Runtime for iOS on Apple TV

Last week Apple announced amongst many new things an update to Apple TV. It now runs on a new operating system named tvOS and includes an app store allowing third-party apps. These apps can be developed using many frameworks and concepts quite familiar to the iOS ones (Foundation, UIKit and CoreGraphics), but also includes some new APIs like TVServices.

We were eager to find out if it was possible to run NativeScript on this new device.

Building the NativeScript Runtime for tvOS

The NativeScript runtime for iOS uses CMake to ease the build configuration process. All we had to do in order to make our build (which includes the JavaScriptCore engine) Apple TV compatible, was to add two more platforms in our config scripts:

set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator;-appletvos;-appletvsimulator")
set(CMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS "iphoneos iphonesimulator appletvos appletvsimulator")

After that the produced NativeScript libraries could be successfully linked in a tvOS project.

Generating Metadata for the tvOS SDK

The second step to running NativeScript on Apple TV was feeding our metadata generator with the new tvOS SDK. We had to make some minor tweaks to the Clang frontend flags, but after that it worked like a charm.

This allowed us to use all tvOS specific APIs immediately and any future one will be generated automatically based on your local tvOS SDK.

Writing a NativeScript App Running on Apple TV

After that it took less than a hundred lines of code to make a beautiful proof of concept app running on the Apple TV simulator:

In this example we are utilizing a UIPageViewController with some images downloaded from imgur. The result is a slideshow-like screen that can be navigated with the Apple TV Remote. You can find the full source code on GitHub.

Feel free to clone the project and experiment with it and tell us what you think. The future of Apple TV looks very promising and we will be watching it closely to see how it progresses.

P.S. Here are also some great resources if you want to learn more about Apple TV apps:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment