您的位置:首页技术文章
文章详情页

ios - 用WXWebComponent代码创建一个新的web组件,出现以下问题

【字号: 日期:2024-04-09 16:18:53浏览:48作者:猪猪

问题描述

我用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;}

问题解答

回答1:

self.schemesCallBacks里存的value是WXCallback?建议换成WXKeepAliveCallback试试

标签: web