URL 要求処理に使用している間、 Phonegap 通知 (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;
}
私を助けてください。