Skip to content

Instantly share code, notes, and snippets.

@geetfun
Created September 10, 2015 21:13
Show Gist options
  • Save geetfun/7b0670abfc96e0792343 to your computer and use it in GitHub Desktop.
Save geetfun/7b0670abfc96e0792343 to your computer and use it in GitHub Desktop.
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"
// MARK: UIApplication Overrides
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let appControllerContext = TVApplicationControllerContext()
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
}
}
appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)
return true
}
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)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment