Skip to content

Instantly share code, notes, and snippets.

@rayh
Created September 21, 2015 03:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rayh/3d8382bb7313f6035c6e to your computer and use it in GitHub Desktop.
Save rayh/3d8382bb7313f6035c6e to your computer and use it in GitHub Desktop.
Setup console.log() for TVJS apps
func appController(appController: TVApplicationController, evaluateAppJavaScriptInContext jsContext: JSContext) {
jsContext.evaluateScript("var console = {log: function() { var message = ''; for(var i = 0; i < arguments.length; i++) { message += arguments[i] + ' ' }; console.print(message) } };")
let logFunction: @convention(block) (NSString!) -> Void = { (message:NSString!) in
print("JS: \(message)")
}
jsContext.objectForKeyedSubscript("console").setObject(unsafeBitCast(logFunction, AnyObject.self), forKeyedSubscript:"print")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment