iOS UIWebView Javascript - insert data -receive callbacks?

后端 未结 3 1873

I have a webpage. I have a javascript file that does a whole lot of stuff. In the app I have an NSString with some crucial data that needs to be processed in the javascrip

3条回答
  •  醉话见心
    2020-12-07 20:14

    - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
    

    sounds like exactly the method you need. If, for example, the input and output need to interact with the JavaScript can be done with a single method, you can pass a value into JavaScript and get the results with something like the following code:

    NSString* jsCode = [NSString stringWithFormat:@"doSomething('%@')", dataToPass];
    NSString* resultFromJavaScript = [webView stringByEvaluatingJavaScriptFromString:jsCode];
    

提交回复
热议问题