wkwebviewconfiguration

JS calling a function in Swift

本小妞迷上赌 提交于 2019-11-29 21:59:40
问题 I know how to send message from JS to native IOS swift app: func userContentController(userContentController: WKUserContentController!, didReceiveScriptMessage message: WKScriptMessage!) { println("JavaScript is sending a message \(message.body)") } and JS: webkit.messageHandlers.callbackHandler.postMessage("Hello from JavaScript"); My question: is it possible to directly call a function in the native app rather then receiving the message in my example code. say i want in the JS to use

WKWebview evaluateJavascript is not working, throws an error

限于喜欢 提交于 2019-11-29 05:48:18
I am trying to call an existent function from a remote site in a WKWebview: function addtext (text) { jQuery("#webviewtest").html(text); } With: [self.WebView evaluateJavaScript:@"addtext(\"This is a text from app\");" completionHandler:^(id Result, NSError * error) { NSLog(@"Error -> %@", error); }]; But this is throwing an error: Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo=0x170c788c0 {NSLocalizedDescription=A JavaScript exception occurred} This is so simple! I am must missing something really stupid! Found a solution, it was simple as I was expecting, I was

How to delete WKWebview cookies

大憨熊 提交于 2019-11-26 07:34:17
问题 For now I am doing like this NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]) { [storage deleteCookie:cookie]; } But it is not working on iOS 8, 64-bit device. Any other way the clean cookies of WKWebview? Any help will be appreciated. thanks. 回答1: Apple released new APIs for iOS 9 , so now we can remove domain specific cookies stored for WKWebView with below code, but this will only work on devices with iOS