Skip to content

Instantly share code, notes, and snippets.

@BradBroulik
Created October 5, 2015 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BradBroulik/3ebd5d3eaed7bd3014bf to your computer and use it in GitHub Desktop.
Save BradBroulik/3ebd5d3eaed7bd3014bf to your computer and use it in GitHub Desktop.
TVMLKit AppDelegate
import UIKit
import TVMLKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDelegate {
var window: UIWindow?
var appController: TVApplicationController?
static let TVBaseURL = "http://localhost:9001/"
static let TVBootURL = "\(AppDelegate.TVBaseURL)js/application.js"
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let appControllerContext = TVApplicationControllerContext()
if let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) {
appControllerContext.javaScriptApplicationURL = javaScriptURL
}
/*
Set the properties that will be passed to the `App.onLaunch` function
in JavaScript.
*/
appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL
if let options = launchOptions {
for (kind, value) in options {
if let kindStr = kind as? String {
appControllerContext.launchOptions[kindStr] = value
}
}
}
self.appController = TVApplicationController(context: appControllerContext, window: self.window, delegate: self)
return true
}
// MARK: TVApplicationControllerDelegate
func appController(appController: TVApplicationController, didFinishLaunchingWithOptions options: [String: AnyObject]?) {
print("\(__FUNCTION__) invoked with options: \(options)")
}
func appController(appController: TVApplicationController, didFailWithError error: NSError) {
print("\(__FUNCTION__) invoked with error: \(error)")
let title = "Error Launching Application"
let message = error.localizedDescription
let alertController = UIAlertController(title: title, message: message, preferredStyle:.Alert )
self.appController?.navigationController.presentViewController(alertController, animated: true, completion: { () -> Void in
// ...
})
}
func appController(appController: TVApplicationController, didStopWithOptions options: [String: AnyObject]?) {
print("\(__FUNCTION__) invoked with options: \(options)")
}
}
@BradBroulik
Copy link
Author

A simple AppDelegate for TMVLKit. Edit AppDelegate.TVBaseURL as necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment