iOS 混合网页开发 问题
2015-10-19 11:02
483 查看
在利用JavaScriptCore与H5交互时出现异常提示:
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.
从字面意思看,是因为在后台线程修改了UI,于是乎开始验证
果然,在XCode7中网页交互实在后台线程中执行的(XCode6木有问题),所以在交互时修改UI要再主线程中执行,问题解决。
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.
从字面意思看,是因为在后台线程修改了UI,于是乎开始验证
_weak typeof(self)weakSelf = self; JSContext *tContext = [weakSelf.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; tContext[@"jsredirect"] = ^(){ NSArray *tArgs = [JSContext currentArguments]; JSValue *tJSValue = [tArgs firstObject]; @try { NSDictionary *tActionValueDic = [tJSValue toDictionary]; NSLog(@"JSValue:%@", tActionValueDic); NSString *tUrlStr = tActionValueDic[@"url"]; if ([tUrlStr isEqualToString:@"chartDispose"]) { [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"]; [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"]; [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"]; [[NSUserDefaults standardUserDefaults] synchronize]; }else{ CGGradeJumpWebViewController *vc = [[CGGradeJumpWebViewController alloc]init]; vc.urlStr = tUrlStr; NSLog(@"Current Thread:%@",[NSThread currentThread]); dispatch_async(dispatch_get_main_queue(), ^{ //UI修改 NSLog(@"Current Thread:%@",[NSThread currentThread]); [weakSelf.navigationController pushViewController:vc animated:YES]; }); } } @catch (NSException *exception) { NSLog(@"exception:%@", exception); } };
果然,在XCode7中网页交互实在后台线程中执行的(XCode6木有问题),所以在交互时修改UI要再主线程中执行,问题解决。
相关文章推荐
- iOS 可变参数宏__VA_ARGS__
- iOS 使用CoreLocation定位
- how to create a framework for ios . cool!
- iOS设计模式——Category
- [iOS]Reason: image not found 解决办法
- iOS—懒加载模式
- iOS7之后隐藏状态栏
- iOS使用Charles(青花瓷)抓包并篡改返回数据图文详解
- iOS-拆分stroyboard
- iOS开发必备的调试利器
- iOS xcode设置
- iOS 代码添加约束—VFL (AutoLayout)
- iOS开发:iOS TableViewCell自定义分割线
- iOS 单例模式
- iOS - CocoaPods使用
- iOS制作Static Library(静态库),实现多工程的连编
- ios _怕忘记的一些备用代码
- 关于独立完成已有iOS项目《疯狂食材》总结
- IOS下WEB开发细节问题
- (一)iOS平台简介