iOS 开发之崩溃日志分析
2016-03-07 10:46
381 查看
1. (js 与webview 交互崩溃)-[CFRunLoopTimer release]: message sent to deallocated instance 0x62398f80
I've fixed this, just call a dummy stringByEvaluatingJavaScriptFromString on the UIWebView before invoking a method on the context. I believe the reason this works is the call into javascript is done on the Web Thread and it uses a timer to receive the reply back to the main thread, when calling invoke this timer wasn't created so when the reply comes back from the Web Thread it crashes trying to release a timer that was never created in the first place. By using the proper API stringByEvaluatingJavaScriptFromString in insures the timer is created and then the invokeMethod can make use of the same timer.
[/code]
I've fixed this, just call a dummy stringByEvaluatingJavaScriptFromString on the UIWebView before invoking a method on the context. I believe the reason this works is the call into javascript is done on the Web Thread and it uses a timer to receive the reply back to the main thread, when calling invoke this timer wasn't created so when the reply comes back from the Web Thread it crashes trying to release a timer that was never created in the first place. By using the proper API stringByEvaluatingJavaScriptFromString in insures the timer is created and then the invokeMethod can make use of the same timer.
方法一:
JSContext* context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; JSValue* value = context[@"Colors"]; // timer CFRelease crash fix [webView stringByEvaluatingJavaScriptFromString:nil]; [value invokeMethod:@"update" withArguments:@[objectID,modifier]]; 方法二:
NSDictionary *userInfoDic = [self getResponseDicLocationSuccess:isSuccess]; NSString *responseStr = [userInfoDic jsonString]; if (responseStr.length <= 0) { NSAssert(NO, nil); return; } // [NSThread sleepForTimeInterval:1]; dispatch_async(dispatch_get_main_queue(), ^{ if (self.context && responseStr.length > 0) { JSValue *callBackValue = self.context[@"mobileCallback"]; if (callBackValue) { [callBackValue callWithArguments:@[responseStr]]; } } });
[/code]
相关文章推荐
- ios 推送整理
- 一个优化程序效率的调试小技巧
- ContextMenu.iOS
- iOS 使用正则表达式库RegexKitLite的问题
- iOS高效添加圆角效果实战讲解
- iOS重写系统的返回按钮,捕获系统返回按钮事件
- TabBar图标加载不了 -iOS
- iOS 简单push和present混用退回根视图方法
- dismissViewController 实现多个模态VC跳转到根VC
- iOS动画——Layer Animations(三)
- 深入浅出-iOS函数式编程的实现 && 响应式编程概念
- iOS 在viewController中监听Home键触发以及重新进入界面的方法
- iOS动画——Layer Animations(二)
- iOS 25个性能优化/内存优化常用方法
- iOS动画——Layer Animations(一)
- iOS中数组元素的去重样例
- iOS大神技术博客
- iOS开发 ☞ 数组常用方法
- iOS String字符串
- iOS KVC和KVO