how to call a swift function from javascript

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


how to call a swift function from javascript



I am injecting a script in UIWebView using Swift. When a certain tap action happens, the script takes care of the handling. While this happens, the JavaScript is supposed to make a call to one of the functions in Swift, which saves the data sent from JavaScript in native variable. Please help me in making this call.


UIWebView





People won't be able to help without showing what you have done so far. Bits of code snippets would do.
– Jay Mayu
27 mins ago




1 Answer
1



For this you need to make a callback from your JavaScript file, I used one JavaScript editor in that,This was the code :-


window.location = "callback://0/"+ pass your value here



And in your swift file, use the UIWebViewDelegate :-


func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let urlString = request.url?.absoluteString
//NSLog(@"web request");
//NSLog(@"%@", urlString);
if ((urlString?.range(of: "callback://0/")) != nil) {

// We recieved the callback
let value = urlString?.replacingOccurrences(of: "callback://0/", with: "")



}
}





I mainly want to send value of one of the variables in javascript to swift . Can you help.
– Maila
3 mins ago








By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Regex - How to capture all iterations of a repeating pattern?