📜 ⬆️ ⬇️

Apple TV



The development of my first application for Apple TV is coming to an end, and I decided to share the information gathered about this platform.

tvOS supports two types of applications: TVML and traditional.
')
Traditional apps are almost the same as iOS apps (UIKit, Storyboard);
TVML is a framework for creating client-server applications. All logic, design and data are on a remote server.

Input Tools


1. Standard controller - Apple TV Remote (Siri Remote). All functions of the application must be available from it. An application cannot require the use of a third-party controller.
2. GameController - gamepad. There are two types
2.1. Standalone controller - the usual gamepad;
2.2. A device that connects to the iPhone and turns it into a gamepad.
3. In addition, gamepads (both of the above types) are divided into two types - Gamepad Profile and Extended Gamepad Profile. They differ in the number of buttons.
4. All game controllers can be connected via wi-fi and via cable.
5. An application using game controllers must support all of the above (i.e. be able to work with any gamepad connected as you like).
6. The current version of the TV simulator does not support game controllers.
7. Bluetooth LE - a standard controller works through it. Additionally, you can connect no more than two devices. Does not work on the simulator.
8. Bonjour - WiFi connection. Looks most attractive. There is no limit on the number of connected devices. However, here the representative of the eppla writes that the developers themselves will have to determine how many connected devices will be acceptable in terms of performance.
9. CloudKit - data exchange via iCloud.

Included with the TV is Siri Remote - a remote control with a touchscreen, an accelerometer, a gyroscope and a microphone.

1. Touchscreen - supports force touch, gestures. You can access raw data (i.e., touch coordinates)
2. Button “Menu” - works like the button “back” on Android: returns to the previous window. It creates some problems, for example, with boot screens (after loading, the user can return to it). However, it can be redefined in code.
3. Button "Siri" - as the name implies, starts Siri. Unfortunately, can not be used in applications.
4. “Play / Pause” button - can be redefined in code
5. Button "TV" - collapses the application.
6. Volume adjustment.

Learn more about the “Menu” button.

The easiest way to override the “Menu” button is to start a gesture recognizer for it. Add the following code to viewDidLoad () of your ViewController:

let menuClickRecognizer = UITapGestureRecognizer(target: self, action:«menuButtonClicked») menuClickRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)] self.view.addGestureRecognizer(menuClickRecognizer) 

It remains to create the menuButtonClicked function.

 func menuButtonClicked(){ debugPrint(«Menu button clicked!») } 

It should be noted that if the custom gesture recognizer was defined for the “Menu” button, then the standard one stops working. This can cause problems exiting the application. In accordance with this guideline , the Menu button should return the user to the previous screen, and from the first to go to the home screen. The problem can be solved using unwind segue, rather than the usual transition between ViewControllers.

Icons


Quite an interesting feature of the new tvos - Parallax Icons. The application icon can consist of several layers that move beautifully one after another when the focus is shifted. An icon can have from one to five layers, and the first (background) layer should be opaque (it should not have an alpha channel).

In addition, it is possible to use parallax inside the application. For example, for custom buttons.
See how it all looks possible, for example, here .

Top Shelf Image


Top Shelf Image - application “header” on the home screen. It is displayed only for those applications whose icon is in the top line. May be:
1. Normal picture
2. Slideshow
3. Dynamic Content - a set of icons that can be links to any application windows. Apple prohibits using it for advertising.

Restrictions


The size of the application can not exceed 200 MB. This limitation can be circumvented using On-Demand Resources , i.e., dynamically loaded content.

But the saddest limitation is that the application does not have access to the internal storage. The application can not just save anything on the device. Apple suggests using iCloud key-value storage for storing small amounts of information (up to 1 MB) and CloudKit in other cases.

As Apple writes in one of its many guidelines , other Apple products (iPhone, iPad, Mac ...) suggest a single user. Apple TV is targeted at multiple users interacting with the console and with each other.

Creating apps for a group of friends or a family is what Apple expects from tvOS developers.

Source: https://habr.com/ru/post/270457/


All Articles