Search code examples
iphoneios

confirm user wants to call a phone number after click


I want to show a pop up that asks if the user wants to call the number when the user clicks on a number.

How do I do that? Currently, when I click on the number, it calls it automatically.


Solution

  • Create a UIAlertView with the delegate set to self, and if the selectedButtonIndex is the buttonIndex of the yes button in the alert, call the number, if not, don't call the number.

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Do you want to call..." delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    [alert setTag:02];
    [alert show];
    [alert release];
    
    - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
        if (alertView.tag == 02 && buttonIndex != alertView.cancelButtonIndex) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://phonenumber"]];
        }
    }