Created
December 26, 2015 12:47
-
-
Save 0xWDG/ac0e22450cdbd5ce0dc4 to your computer and use it in GitHub Desktop.
Web view add console.log support
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
let jsContext = mainWebview.mainFrame.javaScriptContext | |
jsContext.evaluateScript("var console = {log: function () {var message = '';for (var i = 0; i < arguments.length; i++) {message += arguments[i] + ' '};console.print(message)},warn: function () {var message = '';for (var i = 0; i < arguments.length; i++) {message += arguments[i] + ' '};console.print(message)},error: 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