使用navigator.notification.alert
进行网址请求处理时,手机空间通知(navigator.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;
}
请帮帮我。
答案 0 :(得分:1)
进入非常相似的问题。改变最后一行
return YES;
到
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
插件的所有命令都通过gap:// bridge。每次调用都会调用 shouldStartLoadWithRequest 。因此,默认为是似乎是个问题。实际上,它应该为gap:// calls返回 NO 。