0

用于 URL 请求处理时, Phonegap 通知 (navigator.notification.alertnavigator.notification.confirm) 不起作用。shouldStartLoadWithRequest

Javascript:

function onBodyLoad() {
  document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
  navigator.notification.alert("Cordova is working");
}

目标 C:

- (BOOL)webView:(UIWebView *)webView2
shouldStartLoadWithRequest:(NSURLRequest *)request
  navigationType:(UIWebViewNavigationType)navigationType{
    if ([[[request URL] absoluteString] hasPrefix:@"js-call:"]) {
      // Extract the selector name from the URL
      NSString *requestString = [[request URL] absoluteString];
      NSArray *components = [requestString componentsSeparatedByString:@":"];
      NSString *function = [components objectAtIndex:1];
      NSLog(@"the function name is  %@",function);
      // Call the given selector
      [self performSelector:NSSelectorFromString(function)];
      // Cancel the location change
      return NO;
    }
    return YES;
  }

请帮帮我。

4

1 回答 1

1

遇到非常相似的问题。更改最后一行

return YES;

return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];

插件的所有命令都通过 gap:// 桥。每次这样的调用都会调用shouldStartLoadWithRequest 。因此,默认为YES似乎是问题所在。事实上,它应该为 gap:// 调用返回NO 。

于 2012-07-20T20:25:09.533 回答