tvOS9-TVMLKitDemo
tvOS9-TVMLKitDemo copied to clipboard
tvOS 9 - Experiments - TVApplicationController Javascript Environment (TVMLKit) - AppleTv.
tvOS 9 - New OS - TVMLKit tvOS! - Example
tvOS 9~ Experiments - TVApplicationController Javascript Environment - appleTv.
Example
Pictures Source
Licence CCO Public Domain from : Pixabay.com
Requirements
-
= XCode 8.0.
-
= Swift 3.
-
= tvOS 9.0
Tested on tvOS 9.0 Simulator, Apple Tv Developer Kit.
Important
this is the Xcode 8 / Swift updated project.
App Transport Security Settings
To support HTTP hosted : add the Boolean type Value to YES
for NSAllowsArbitraryLoads
in app's info.plist
file.
Client-Server App
-
Create and configure the client-server app with javascript file :
main.js
-
Create and configure
.tvml
files -
TVML Templates here : Apple TV Markup Language Reference Templates.
Code Example
AppDelegate Class
import TVMLKit
...
// MARK: - Properties
var window: UIWindow?
var appController : TVApplicationController?
static let TVBaseURL = "http://localhost:9001/"
static let TVBootURL = "\(AppDelegate.TVBaseURL)js/main.js"
// MARK: - UIApplication Overrides
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
/// Create the TVApplicationControllerContext
let appControllerContext = TVApplicationControllerContext()
/// Javascript Context for TVMLKit Application
if let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) {
appControllerContext.javaScriptApplicationURL = javaScriptURL
}
appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL
if let launchOptions = launchOptions as? [String: AnyObject] {
for (kind, value) in launchOptions {
appControllerContext.launchOptions[kind] = value
}
}
/// Javascript Environment
appController = TVApplicationController(context: appControllerContext, window: self.window, delegate: self)
return true
}
...
Usage
To run the example project, download or clone the repo. Run client-server app with Terminal command :
python -m SimpleHTTPServer 9001
Build and Run tvOS Simulator!