Phonegap notifications (navigator.notification.alert and navigator.notification.confirm) are not working while using shouldStartLoadWithRequest for URL request processing.
Javascript:
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
navigator.notification.alert("Cordova is working");
}
Objective 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;
}
Please help me out.
Ran into very similar issue. Changing the last line
to
All commands to plugins go through gap:// bridge. shouldStartLoadWithRequest gets called for every such call. So, defaulting to YES appears to be the issue. When in fact, it should return NO for gap:// calls.