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

时间:2015-02-09 09:53:53

标签: ios uiwebview javascriptcore

存在属性@property(非原子,强)JSContext *上下文; 我在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   $0x2c, %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

2 个答案:

答案 0 :(得分:2)

我已经解决了这个问题。

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

答案 1 :(得分:0)

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

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