使用Objective-c捕获JavaScript异步调用

使用Objective-c捕获JavaScript异步调用,javascript,ios,objective-c,uiwebview,uiwebviewdelegate,Javascript,Ios,Objective C,Uiwebview,Uiwebviewdelegate,我用UIWebViewDelegate捕捉javascript调用 它看起来像: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ NSDictionary *dictionary = [[[JSBridgeController alloc] ini

我用
UIWebViewDelegate
捕捉
javascript
调用

它看起来像:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{      
NSDictionary *dictionary = [[[JSBridgeController alloc] init] js:request];
if (dictionary) {
    if ([dictionary[@"methodName"] isEqualToString:@"gimmeUser"]) {
        [self.delegate gimmeUserJS: dictionary];
    }
    if ([ dictionary[@"methodName"] isEqualToString:@"initMe"]) {
        [self.delegate initMeJS: dictionary];
    }
}
return YES;}
对我来说,问题在于网络方面。它有几十个像上面代码中那样的
JS
请求,并异步发送它们。因此,如果我同时收到两个请求,webview代理只能看到其中一个,而忽略另一个

我尝试使用
NSOperationQueue
NSURLConnection sendAsynchronousRequest
,但没有成功

如何为每个异步
JS
请求调用
shouldStartLoadWithRequest
委托


感谢您的帮助。

一种方法是为您的视图生成唯一标识符。
然后,将其存储在字典中,并引用您的视图。然后,您的视图可以通过导航到“callback:callback?id=“+Your_passed_id”返回标识符

if ( [[[inRequest URL] scheme] isEqualToString:@"callback"] ) {
    //then use the query string and parse for id 
    //in order to have individual control over callbacks
    NSString *queryString = [[inRequest URL] query];
}
有关回调模式的mor信息,请参阅:

我知道这很复杂,但这是一个解决方案。。。 祝你好运