- (JSValue *)callWithArguments:(NSArray *)arguments 在 ios7.0.4 中崩溃

- (JSValue *)callWithArguments:(NSArray *)arguments crashed in ios7.0.4

存在一个属性 @属性 (nonatomic, strong) JSContext *context; 我在 webviews 的委托方法中设置了 jscontext。

    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
    [self.indicatorView stopAnimating];
    self.webView.hidden = NO;
    __weak typeof(self) weakSelf = self;
    self.context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    self.context[@"closeWebview"] = ^() {
        weakSelf.dismissViewBlock();
    };
  }

定位成功后调用以下方法:

    - (void)sendUserInfoDicToJSLocationSuccess:(BOOL)isSuccess
    {
    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]];
            }
        }
    });
}

如果我使用时间延迟,效果很好。否则它会在 webcore 线程中崩溃。 错误信息如下

WebCore`void WebCore::StyleResolver::applyMatchedProperties<(WebCore::StyleResolver::StyleApplicationPass)1>(WebCore::StyleResolver::MatchResult const&, bool, int, int, bool):
0x8f3ff40:  pushl  %ebp
0x8f3ff41:  movl   %esp, %ebp
0x8f3ff43:  pushl  %ebx
0x8f3ff44:  pushl  %edi
0x8f3ff45:  pushl  %esi
0x8f3ff46:  subl   [=13=]x2c, %esp
0x8f3ff49:  movl   0x14(%ebp), %edi
0x8f3ff4c:  cmpl   $-0x1, %edi
0x8f3ff4f:  je     0x8f40072 

            ; 

void WebCore::StyleResolver::applyMatchedProperties<(WebCore::StyleResolver::StyleApplicationPass)1>(WebCore::StyleResolver::MatchResult const&, bool, int, 

int, bool) + 306
0x8f3ff55:  movl   0x18(%ebp), %esi
0x8f3ff58:  movl   0xc(%ebp), %ebx
0x8f3ff5b:  movl   0x8(%ebp), %edx
0x8f3ff5e:  movl   0x130(%edx), %eax
0x8f3ff64:  movzwl 0x2c(%eax), %eax

我已经解决了这个问题。

dispatch_async(dispatch_get_main_queue(), ^{
    if (self.context && responseStr.length > 0) {
        JSValue *callBackValue = self.context[@"mobileCallback"];
         [self.context[@"setTimeout"] callWithArguments:@[callBackValue,@0, responseStr]];
    }
});
dispatch_async(dispatch_get_main_queue(), ^{
    if (self.context && responseStr.length > 0) {
        JSValue *callBackValue = self.context[@"mobileCallback"];
         [self.context[@"setTimeout"] callWithArguments:@[callBackValue,@0,     responseStr]];
    }
});

我也解决了这个问题。 谢谢丹尼斯!