启用shouldStartLoadWithRequest方法后,Phonegap(基于Cordova 1.9.0)警报无法正常工作

时间:2012-07-18 07:29:53

标签: javascript iphone cordova

使用navigator.notification.alert进行网址请求处理时,手机空间通知(navigator.notification.confirmshouldStartLoadWithRequest)无效。

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

请帮帮我。

1 个答案:

答案 0 :(得分:1)

进入非常相似的问题。改变最后一行

return YES;

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

插件的所有命令都通过gap:// bridge。每次调用都会调用 shouldStartLoadWithRequest 。因此,默认为似乎是个问题。实际上,它应该为gap:// calls返回 NO