Back to Blog Home
← all posts

Running the NativeScript Runtime for iOS on Apple TV

September 17, 2015 — by Jason Zhekov

Last week, amongst many new things, Apple announced an update to the 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 similar to iOS ones (Foundation, UIKit and CoreGraphics), but also some new APIs like TVServices.

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

NativeScript TV

This can be beneficial to you in several ways. First, you will be able to access the native TV UI using JavaScript, and second and more important - you will be able to reuse any existing business logic, or cloud connectivity you probably already have in place as part of your web or mobile application. Not to mention that you are now a TV developer using NativeScript :).

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 way we invoke the Clang compiler which we use to generate metadata about native APIs, but after that it worked like a charm.

This allowed us to use all tvOS specific APIs immediately and any future ones 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:

UIPageViewController with NativeScript running on Apple TV

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.

If you plan to work on tvOS, please get in touch with us so that we can work together and help you build your solution. The best way to get in touch is to open an issue on GitHub.

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