2012-07-18 22 views
0

对URL请求处理使用shouldStartLoadWithRequest时,Phonegap通知(navigator.notification.alertnavigator.notification.confirm)不起作用。当启用shouldStartLoadWithRequest方法时,Phonegap(基于Cordova 1.9.0)警报不起作用

的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

跑到非常类似的问题。最后一行

return YES; 

更改为

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

所有命令插件经过间隙://桥梁。每个此类调用都会调用shouldStartLoadWithRequest来调用。所以,默认为YES似乎是问题所在。实际上,它应该返回NO作为gap://调用。

+0

它为我工作。非常感谢。 – prodeveloper 2012-08-09 07:36:42