我正在使用以下代码来检测是否在UIWebView中单击了链接并显示警报。因此用户需要确认离开应用程序。地址检测也有效。如果用户点击地址,您可以直接从Apple切换到Google地图应用。我想在切换到地图应用之前检测到这一点以显示警报。如何检测UIWebView中是否单击了地址(位置)?
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
savedLink = [request URL];
if ( ( [ [ savedLink scheme ] isEqualToString: @"http" ] || [ [ savedLink scheme ] isEqualToString: @"https" ]) && ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
UIAlertView *leaveApp = [[UIAlertView alloc]initWithTitle:@"Warning!" message:@"You want to leave the app?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[leaveApp show];
return NO;
}
return YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Yes"])
{
[[UIApplication sharedApplication] openURL:savedLink];
}
else if([title isEqualToString:@"No"])
{
//do nothing
}
}
答案 0 :(得分:0)
我期待像maps.apple.com这样的东西,但该方案被称为x-apple-data-detector。 如果我正在寻找那个计划,它正在发挥作用。
[[savedLink scheme] isEqualToString:@"x-apple-data-detectors"]