diff --git a/JavaScriptCore-Demo/JSCallOC/JSCallOC.html b/JavaScriptCore-Demo/JSCallOC/JSCallOC.html index 6a06330..a4fcfa9 100644 --- a/JavaScriptCore-Demo/JSCallOC/JSCallOC.html +++ b/JavaScriptCore-Demo/JSCallOC/JSCallOC.html @@ -70,7 +70,7 @@

- +

diff --git a/JavaScriptCore-Demo/JSCallOC/JSCallOCViewController.m b/JavaScriptCore-Demo/JSCallOC/JSCallOCViewController.m index f8290c7..3cb66c2 100644 --- a/JavaScriptCore-Demo/JSCallOC/JSCallOCViewController.m +++ b/JavaScriptCore-Demo/JSCallOC/JSCallOCViewController.m @@ -72,8 +72,12 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView self.context[@"alert"] = ^(NSString *str) { - UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"msg from js" message:str delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; - [alert show]; + //要把改变视图的操作放到主线程中,否则就会抛出异常,对以后的操作会有问题 + [[NSOperationQueue mainQueue]addOperationWithBlock:^{ + + UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; + [alert show]; + }]; }; __block typeof(self) weakSelf = self; diff --git a/README.md b/README.md index 64cfc26..edff5ea 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,14 @@ JavaScriptCore-Demo =================== JavaScriptCore.framework :iOS7 中新加入的框架,用来处理JavaScript。JavaScriptCore 是苹果 Safari 浏览器的 JavaScript 引擎,JavaScriptCor在 OS X 平台上很早就存在的,而在 iOS 平台,直到IOS7才对外开放,并提供了 Objective-C 的接口 + +==================== +Edited by Winzlee + +注:在JSCallOC中,当创建原生的UIAlertView的时候,需要把代码放到主线程中,否则就会因为在后台修改了视图而抛出异常,会在以后的操作中有影响。 + + [[NSOperationQueue mainQueue]addOperationWithBlock:^{ + + UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; + [alert show]; + }];