Created
October 5, 2015 22:45
-
-
Save BradBroulik/3ebd5d3eaed7bd3014bf to your computer and use it in GitHub Desktop.
TVMLKit AppDelegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple AppDelegate for TMVLKit. Edit AppDelegate.TVBaseURL as necessary.