webview 页面返回原生页面
方法就是在html5 代码中添加:
function chooseCar(){ //为按钮的点击时间
var url="testapp:";
document.location = url;
}
然后实现代理方法
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ( components.count >0&&[(NSString *)[components objectAtIndex:0] isEqualToString:@"testapp"]) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Alert from Cocoa Touch" message:@"test"
delegate:self cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
return NO;
}
return YES;
}