Show alert view when click on a link

给你一囗甜甜゛ 提交于 2019-12-31 03:06:14

问题


I use formatted text in UIWebView, i have something like this:

<a href="tel://0442059840">0442059840</a>

I need to show alert to the user when clicking on that link using the UIAlertView for confirmation before launching the telephone call. Is this possible? Thanx in advance.


回答1:


Yes but you need to use undocumented method for this. Search on google or stackoverflow you will find it easily. Here is a link for helping you.

http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/




回答2:


Override the delegate method

webView:shouldStartLoadWithRequest:navigationType:

and do the cjhanges as in the code I added.

Following code may help you :

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    NSString *urlString = [url absoluteString];
    if([urlString isEqualToString:@"tel://0442059840"])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Title", nil)
                                                        message:NSLocalizedString(@"Message", nil)
                                                       delegate:nil
                                              cancelButtonTitle:NSLocalizedString(@"OK", nil)
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    return YES;
}


来源:https://stackoverflow.com/questions/6593991/show-alert-view-when-click-on-a-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!