如何在ios中运行java脚本,直到" DONE"
UIViewController *webViewController = [[UIViewController alloc] init];
UIWebView *uiWebView = [[UIWebView alloc] initWithFrame: CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlToken]]];
NSString *javaScript=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BOJavaScript" ofType:@"js"] encoding:NSUTF8StringEncoding error:nil];
[uiWebView stringByEvaluatingJavaScriptFromString:javaScript];
答案 0 :(得分:0)
方法stringByEvaluatingJavaScriptFromString
在主线程上运行(UIWebView
是一个UI元素),它返回NSString
。不需要等待"作出回应。
答案 1 :(得分:0)
在MainViewController.h文件中
@interface MainViewController :<UIWebViewDelegate>
在文件MainViewController.m
中- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *javaScript=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BOJavaScript" ofType:@"js"] encoding:NSUTF8StringEncoding error:nil];
[uiWebView stringByEvaluatingJavaScriptFromString:javaScript];
}