在利用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,于是乎开始验证

_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要再主线程中执行,问题解决。

最新文章

  1. webService学习之路(二):springMVC集成CXF快速发布webService
  2. 本周psp个人作业
  3. LUXURY 8
  4. 使用culr
  5. 记录一些容易忘记的属性 -- UILabel
  6. Flash Builder 4.6 BUG 远程访问受阻
  7. Linux----给一个普通用户root权限
  8. doubango地址配置
  9. 【资料总结】| Deep Reinforcement Learning 深度强化学习
  10. net license tool, EasyLicense !
  11. D. Duff in Beach
  12. 将GPS获得的UTC时间转换成本地时间的方法(转)
  13. Utils--字符串的帮助类
  14. IOS初级:SDWebImage
  15. Postgres 的 JSON / JSONB 类型
  16. 用FadingActionBar实现有头图的ActionBar
  17. Informatica 常用组件Lookup之三 关系和平面文件查找
  18. LeetCode-Evaluate Reverse Polish Notation[AC源码]
  19. 【组合数】【乘法逆元】 Codeforces Round #404 (Div. 2) D. Anton and School - 2
  20. 一道超级坑爹的水题(ACdream oj 无耻的出题人)

热门文章

  1. GitHub使用心得
  2. 《利用Python进行数据分析: Python for Data Analysis 》学习随笔
  3. HDU 4605 Magic Ball Game (dfs+离线树状数组)
  4. ios8 设置单元格分割线无效
  5. C# Winform TreeView 的一些基本用法
  6. Mysql的一些使用
  7. C# 读取 CSV 文件
  8. C++: virtual inheritance and Cross Delegation
  9. 无题的题 & 模拟退火...
  10. 如何打开VPK文件?里面究竟有什么?