-
-
Save md2k/73af28d0d0c73deb80b3 to your computer and use it in GitHub Desktop.
Setup console.log() for TVJS apps
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
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