iOS JavaScriptCore与H5交互时出现异常提示
2024-10-11 20:14:19
在利用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要再主线程中执行,问题解决。
最新文章
- webService学习之路(二):springMVC集成CXF快速发布webService
- 本周psp个人作业
- LUXURY 8
- 使用culr
- 记录一些容易忘记的属性 -- UILabel
- Flash Builder 4.6 BUG 远程访问受阻
- Linux----给一个普通用户root权限
- doubango地址配置
- 【资料总结】| Deep Reinforcement Learning 深度强化学习
- net license tool, EasyLicense !
- D. Duff in Beach
- 将GPS获得的UTC时间转换成本地时间的方法(转)
- Utils--字符串的帮助类
- IOS初级:SDWebImage
- Postgres 的 JSON / JSONB 类型
- 用FadingActionBar实现有头图的ActionBar
- Informatica 常用组件Lookup之三 关系和平面文件查找
- LeetCode-Evaluate Reverse Polish Notation[AC源码]
- 【组合数】【乘法逆元】 Codeforces Round #404 (Div. 2) D. Anton and School - 2
- 一道超级坑爹的水题(ACdream oj 无耻的出题人)
热门文章
- GitHub使用心得
- 《利用Python进行数据分析: Python for Data Analysis 》学习随笔
- HDU 4605 Magic Ball Game (dfs+离线树状数组)
- ios8 设置单元格分割线无效
- C# Winform TreeView 的一些基本用法
- Mysql的一些使用
- C# 读取 CSV 文件
- C++: virtual inheritance and Cross Delegation
- 无题的题 &; 模拟退火...
- 如何打开VPK文件?里面究竟有什么?