如何使用本机Objective-C方法从本地HTML5文件中的javascript函数调用本机Objective-C方法,反之亦然?

Adr*_*ais 2 javascript xcode objective-c

我想调用一个JavaScript函数,如:

- (void)alertMe:(NSString *)msg {
[[[UIAlertView alloc] initWithTitle:@"Alert" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
Run Code Online (Sandbox Code Playgroud)

function alertMe(msg) {
alert(msg);
}
Run Code Online (Sandbox Code Playgroud)

如果在XCode中的UIWebView上加载HTML文件,如何使用XCode调用它

lan*_*rew 6

使用委托方法UIWebView

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

为你的javascript函数实现查询字符串