(Part 2 of 5)
This is the second part of our tvOS tutorial. Please check out the previous Article to know more about this series.
First make sure you have Xcode 14.1 or later installed and open on your machine.
Then go to File\New\Project and select the tvOS\App template, and click Next.
For the ProductName enter SampleTVML, for the Language select Swift, make sure both checkboxes are unchecked, and click Next.
Choose a directory to save your project and click Save. Xcode will create a empty project for you with a Storyboard (which you would use if you were creating a tvOS custom App).
However, you won’t need that because you are making a TVML app, which uses TVML files to display the UI rather than a Storyboard. So delete Main.storyboard and ViewController.swift from your project.
Next, head into the Info.plist and remove the Main.storyboard file base name key. Finally add a new value “App Transport Security Settings”, and as its child, add Allow Arbitrary Loads and set the value to YES.
Note: Adding this key to your Info.plist is necessary because as of iOS 9, your app will prevent linking to non-HTTPS servers to encourage best practices. In this tutorial, you’ll be testing against a local server without HTTPS enabled, so you’ll disable the default behaviour.
Loading your TVML
Open AppDelegate.swift and do the following:
- Delete all the methods
- Import TVMLKit
- Have your app delegate conform to TVApplicationControllerDelegate
Your AppDelegate.swift should look like this:
Next add the following variables to the class:
· TVApplicationController : A class in TVMLKit that handles communicating with the server.
· TVBaseURL : Contains the path to your server.
Next add the following method to the class (in your AppDelegate.swift):
Explanation of the code:
- Here you are creating a TVApplicationControllerContext, which you will use to initialise your TVApplicationController.
- This contains two bits of information, i.e., [TVBaseURL & TVBootURL].