CHAPTER 1

image

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.

Image 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.

Capabilities

The capabilities of the new Apple TV include:

  • 64-bit A8 processor
  • 32GB or 64GB of storage
  • 2GB of RAM
  • 10/100 Mbps Ethernet
  • Wi-Fi 802.11a/b/g/n/ac
  • 1080p resolution
  • HDMI
  • New Siri Remote/Apple TV Remote
  • Bluetooth capability

Inherited iOS Frameworks

Many of the frameworks available for iOS are available for tvOS. These include:

  • Accelerate
  • AudioToolbox
  • AudioUnit
  • AVFoundation
  • AVKit
  • CFNetwork
  • CloudKit
  • CoreBluetooth
  • CoreData
  • CoreFoundation
  • CoreGraphics
  • CoreImage
  • CoreLocation
  • CoreMedia
  • CoreSpotlight
  • CoreText
  • CoreVideo
  • Darwin
  • Foundation
  • GameController
  • GameKit
  • GameplayKit
  • GLKit
  • ImageIO
  • MachO
  • MediaAccessibility
  • MediaPlayer
  • MediaToolbox
  • Metal
  • MetalKit
  • MetalPerformanceShaders
  • MobileCoreServices
  • ModelIO
  • OpenGLES
  • SceneKit
  • Security
  • simd
  • SpriteKit
  • StoreKit
  • Swift Standard Library
  • SystemConfiguration
  • UIKit

The Apple A8 Processor

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).

9781484217146_Fig01-01.jpg

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):

  1. Touch surface. Swipe to navigate. Press to select. Press and hold for contextual menus.
  2. Menu. Press to return to the previous menu.
  3. Siri/Search. Press and hold to talk in those countries that have the Siri Remote. In all other countries, press to open the onscreen search app.
  4. Play/Pause. Play and pause media.
  5. Home. Press to return to the Home screen. Press twice to view open apps. Press and hold to sleep.
  6. Volume. Control TV volume.
  7. Lightning connector. Plug-in for charging

9781484217146_Fig01-02.jpg

Figure 1-2. Apple’s Siri Remote

Apple TV’s Limitations

The tvOS and iOS are very similar, however, there are several differences and limitations:

  • Users can’t tap their screens: Users will find it frustrating using the remote to enter data into a tvOS app. They will likely experience this right away when entering user names and passwords. They may have to retype their entire password if they got distracted and forgot where they left off. Users will find it very helpful to pair a Bluetooth keyboard with their Apple TV when this feature becomes available.
  • No persistent local storage: tvOS offers no persistent local storage. The lack of local storage means any app maker must use CloudKit, Parse, or some other cloud-based service to save files or any other significant amount of information within their app.
  • Developers can only access 500KB of persistent storage. This is what is local to the device to save basic app settings and configuration information using the NSUserDefaults class. Only the temporary and cache directories can be written to. The standard documents directory is not accessible.
  • There is a 200MB app size limit: tvOS enforces a 200MB limit on the size of each app. This will affect a number of apps, especially games. Game apps can easily reach 1GB due to the inclusion of graphic assets. Apps will have to use App Thinning and On-Demand Recourses to download additional assets when needed to address this restriction.
  • No web views: This is probably the most drastic restriction that developers are going to have to work with; especially for apps that are mostly web views. Apple does offer an alternative in the form of TVML. This enables developers to define their views to create a client-server app with the TVJS JavaScript APIs. This also means it will be more difficult to view Word documents and PDFs that were easily viewable in UIWebviews with iOS.
  • No built-in PiP. Picture-in-Picture was introduced in iOS 9 but is not available with tvOS.
  • No customizable video player: The built-in video player in AVKit for tvOS does not support the ability to extend customizations.
  • No photos access: tvOS does support viewing photos stored in iCloud, but developers don’t have the ability to display the photo picker via UIKit’s UIImagePickerController or the Photos framework.
  • No address book, calendar, or iMessage: Apps will not be able to incorporate the Address Book, Contacts, or EventKit frameworks. The MessagesUI framework also isn’t available, making it impossible to send iMessages.
  • No ReplayKit: ReplayKit is targeted at game developers and lets players record their gameplay to share with other players online. It is possible the reason for this omission is that the Apple TV isn’t powerful enough to record 1080p gameplay while rendering the actual game.
  • No Pasteboard API: Pasteboard enables copy and paste functionality on iOS but it is not available for tvOS.
  • No multipeer connectivity: The multipeer connectivity framework handles identifying iOS devices via Wi-Fi, peer-to-peer Wi-Fi, and Bluetooth, and then managing the transfer of data between devices.
  • No Mach Messages and Named Pipes: Mach Messages and Named Pipes are low-level kernel technologies that enable interprocess communications. This enables processes to pass messages to each other.

Advantages with tvOS Development

The Apple TV and tvOS are new, and that brings several advantages over iOS development, at least for now:

  • You only need to develop for a single screen resolution.
  • There is no need to handle screen rotations or size class changes.
  • Unlike mobile cell phones and tablets, tvOS developers can assume the presence of low-latency, always on, high-bandwidth networks.

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 Advantages

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.

9781484217146_Fig01-03.jpg

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:

  • UIButton
  • UIControl
  • UISegmentedControl
  • UITabBar
  • UITextField
  • UISearchBar

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

  1. Read the Human Interface Guidelines for tvOS. You can read the HIG for tvOS at https://developer.apple.com/tvos/human-interface-guidelines/.
  2. If you haven’t already registered for a developer account, go register! You can register at https://developer.apple.com.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset