2

I catch javascript calls with UIWebViewDelegate.

It looks like:

- (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;}

The problem is on the web side for me. It has dozens such JS requests as in above code and send them asynchronous. So if I get two request same time the webview delegate can see only one of them and ignore the other one.

I tried to use NSOperationQueue and NSURLConnection sendAsynchronousRequest but without any success.

How could I invoke shouldStartLoadWithRequest delegate for each async JS request?

Thanks for any help..

Bug
  • 2,576
  • 2
  • 21
  • 36

1 Answers1

0

One way of going about this would be to generate a unique identifier for your view.
Then, store it in a dictionary with references to your views. Your views can then pass the identifier back by navigating to "callback:callback?id="+your_passed_id in your JS.

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];
}

for mor info on the callback pattern see: Javascript in UIWebView callback to C/Objective-C

I know it's complicated, but it's a solution... Good luck!

Community
  • 1
  • 1
Tarik
  • 118
  • 1
  • 10