iOS 开发之崩溃日志分析
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.
方法一:
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]];
}
}
});