ios - 用WXWebComponent程式碼建立新的web元件,出現以下問題
phpcn_u1582
phpcn_u1582 2017-05-31 10:32:17
0
1
753

我用weex本身提供的WXWebComponent程式碼,從新寫了一個自己的WebComponent,並添加了攔截Url請求的方法,暴露給weex檔案使用。

問題描述

每次當我從myWebView攔截Url跳到一個weex文件,再次pop回來的時候,再點擊myWebView的時候,就沒辦法將callback事件回傳給weex檔。並出現以下錯誤提示

WeexDemo[23225:9905854] void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

貼出我的webView攔截Url的部分程式碼

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (_startLoadEvent) {
        NSMutableDictionary<NSString *, id> *data = [NSMutableDictionary new];
        [data setObject:request.URL.absoluteString ?:@"" forKey:@"url"];
        [self fireEvent:@"pagestart" params:data];
    }
    
    NSString * urlAbsoluteString= [request.URL absoluteString];
    NSArray <NSString *>*schemes = self.schemesCallBacks.allKeys;
    for (NSString *scheme in schemes) {
        NSError *error = nil;
        NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:scheme options:NSRegularExpressionCaseInsensitive error:&error];
        if (!error) {
            NSRange range = [regExp rangeOfFirstMatchInString:urlAbsoluteString options:NSMatchingReportProgress range:NSMakeRange(0, urlAbsoluteString.length)];
            if (range.location != NSNotFound) {
                WXCallback callBack = self.schemesCallBacks[scheme];
                callBack(@{@"url": [request.URL absoluteString]});
                return NO;
            }
        } else {
            WXLog(@"created regExp error:  %@", error);
        }
    }
    return YES;
}
phpcn_u1582
phpcn_u1582

全部回覆(1)
Peter_Zhu

self.schemesCallBacks裡存的value是WXCallback?建議換成WXKeepAliveCallback試試

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板