From c273a692bd56e159130c95535640816e2216128e Mon Sep 17 00:00:00 2001 From: Winzlee Date: Tue, 22 Dec 2015 20:01:00 +0800 Subject: [PATCH 1/4] Update JSCallOCViewController.m --- JavaScriptCore-Demo/JSCallOC/JSCallOCViewController.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; From 2f320b5d6d43206b505794dda055b3bcaa30477a Mon Sep 17 00:00:00 2001 From: Winzlee Date: Tue, 22 Dec 2015 20:02:11 +0800 Subject: [PATCH 2/4] Update JSCallOC.html --- JavaScriptCore-Demo/JSCallOC/JSCallOC.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@

- +

From 259a8103cc230d349e6e931c59c6daac941bbd33 Mon Sep 17 00:00:00 2001 From: Winzlee Date: Fri, 25 Dec 2015 10:46:48 +0800 Subject: [PATCH 3/4] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 64cfc26..71eb621 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,12 @@ 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]; + }]; From 9521fd042af4eaea137c59a1e16fbf5f98b40f03 Mon Sep 17 00:00:00 2001 From: Winzlee Date: Fri, 25 Dec 2015 10:47:40 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71eb621..edff5ea 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,10 @@ JavaScriptCore-Demo JavaScriptCore.framework :iOS7 中新加入的框架,用来处理JavaScript。JavaScriptCore 是苹果 Safari 浏览器的 JavaScript 引擎,JavaScriptCor在 OS X 平台上很早就存在的,而在 iOS 平台,直到IOS7才对外开放,并提供了 Objective-C 的接口 ==================== -Edited by Winzlee +Edited by Winzlee + 注:在JSCallOC中,当创建原生的UIAlertView的时候,需要把代码放到主线程中,否则就会因为在后台修改了视图而抛出异常,会在以后的操作中有影响。 + [[NSOperationQueue mainQueue]addOperationWithBlock:^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];