Getting Started with the New Apple TV
Finally! For years iOS developers have been waiting to write apps for the Apple TV. Three years ago, we read in Steve Jobs’s biography that Apple had been working on a new Apple TV, and the current Apple TV was “just a hobby.” In the summer of 2015, Apple finally announced the new Apple TV along with the operating system called tvOS. Developers can now write apps for the Apple TV, and there is a new App Store for tvOS apps.
Note If you haven’t already read the Introduction to this book, take the time to do so. The Introduction covers how to access the free tvOS forum, source code used in this book, free YouTube tvOS training videos, and how to learn Swift 2.
Lots of Good News
There are a lot of great things about the Apple TV. It is important that you understand what the Apple TV is capable of so that you can use these capabilities in your tvOS apps.
The capabilities of the new Apple TV include:
Many of the frameworks available for iOS are available for tvOS. These include:
The Apple TV processor is a 64-bit ARM-based system on a chip (SoC) designed by Apple and manufactured by TSMC. It contains two billion transistors, twice as many as the previous A7 processor.
The A8 processor was first introduced in the iPhone 6 and iPhone 6 Plus. The A8 has 25% more CPU performance and 50% more graphics performance while drawing only 50% of the power compared to its predecessor, the A7 (see Figure 1-1).
Figure 1-1. Apple’s A8 processor, used in the fourth-generation Apple TV
The Siri Remote
The Siri Remote has the following buttons (see Figure 1-2):
Figure 1-2. Apple’s Siri Remote
The tvOS and iOS are very similar, however, there are several differences and limitations:
Advantages with tvOS Development
The Apple TV and tvOS are new, and that brings several advantages over iOS development, at least for now:
Some Notes About Developing in Swift with tvOS
When the Apple TV and tvOS were introduced, the Swift programming language had been available for over a year. We had each been using Objective-C for over six years, but immediately started using Swift for new app development. We will be using Swift in this book.
Although we love developing in Swift, we feel there are a few caveats about Swift we must disclose.
Swift Pain Points
The Swift language is changing and changing fast. Some releases of Swift cause compiler errors in code that worked just fine in the previous Swift version. Although the changes are usually minimal and improve the language, the compiler errors still take time to fix.
Developer tools are still lagging behind Objective-C. Sometimes the debugger refuses to disclose variable results, and compiler errors can be vague or misleading. It’s hard to believe that a year and a half since the introduction of Swift the Refactor command in Xcode still does not work!
Compiler stability can be an issue. Sometimes Xcode will crash, and heavy use of Swift frameworks sometimes don’t work well with “whole module optimization.”
Swift may not be completely mature yet, but it is ready for prime time. It is a pleasure to code in Swift and we have noticed about a third of the code you would have to write in Objective-C is no longer necessary in Swift. For example, Interface Sections are no longer necessary in Swift.
Swift does fulfill the promise of more efficient and modern development. An entire class of errors that used to require runtime debugging are now caught by the compiler. We spend about a quarter of the time debugging Swift apps than we would have with Objective-C.
The tvOS Focus Engine
Interactions in tvOS present a unique challenge to developers and user interface designers. The new Apple TV pairs a remote and a potential wireless game controller with a user interface that lacks a traditional cursor. This results in “focus” being the only way an app can provide visual feedback to users as they navigate within the app.
The focus engine can be thought of as a bridgekeeper between users and your tvOS application. Understanding the focus engine is an essential step toward building an app that feels native to tvOS, and not just a quick, ugly iOS port.
Every experienced iOS developer will feel comfortable with UIKit and tvOS, and Apple has made it easy to port your iOS app to tvOS. However, if you don’t consider how your app needs to interact with the focus engine from the start, you will find yourself frustrated with the user interaction as you finish your app.
What Does Focusable Mean?
Users navigate a tvOS application by moving focus between user interface (UI) items on their TVs. When a UI item is focused, its appearance is adjusted to stand out from the appearance of other items. Focus effects are what make the new Apple TV and tvOS communal. Focus effects provide visual feedback not only to whoever is using the remote, but also to friends and family who may be watching. This is what separates the native tvOS experience from AirPlaying your iPhone or iPad app onto the TV.
Only one view can be in focus at a time, and only views can receive focus. Consider the buttons in Figure 1-3.
Figure 1-3. Button C is focusable
Button C is currently in focus. Swiping left of the Apple TV remote will focus button B. Swiping right on the Apple TV remote will focus button D. Swiping left or right more aggressively will focus button A or button E, respectively.
Apple has updated UIKit and provided implementations for views that can become focusable by providing a method called canBecomeFocused().
Only the following UIKit classes can become focused:
Summary
The new Apple TV offers a great opportunity for developers. The tools that are available in tvOS enable developers to deploy a new generation of apps on a new device in users’ homes.
Exercises