简体   繁体   中英

Dial number in iOS really need confirmation?

I am using the following code to dial number and testing with my device. It seems no confirmation is needed, correct?

NSURL *url = [NSURL URLWithString:@"tel://12345678"];
[[UIApplication sharedApplication] openURL:url];

An alternative to the suitable solution already posted, you could consider using the telprompt URL scheme, eg

NSURL *url = [NSURL URLWithString@"telprompt://12345678"];
[[UIApplication sharedApplication] openURL:url];

Confirmation isn't required and isn't shown when done programmatically. You will only see the alertView in Safari if a number is clicked.

However, in my own experience, I believe it's more convenient for the customer to see a dialog box so they don't accidentally call someone. People just tap things in apps without even thinking and that could be bad in this case.

To mimic what safari does you can do something like this:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Call 12345678?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
[alert show];
alert.tag = 1;
[alert release];

and

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (alertView.tag) {
        case 1:
            if (buttonIndex == 1) {
                NSURL *url = [NSURL URLWithString:@"tel://12345678"];
                [[UIApplication sharedApplication] openURL:url];
            }
            break;
        default:
            break;
    }
}

Confirmation isn't required but it's desirable as it prevents confusion when users are dropped into the dialing application. one thing that you can do that was suggested by another answer is to use telprompt rather then just tel. This will provide the prompt that's necessary via a simple dialog. It also has a very nice side-effect of dropping users back into the calling application after the phone call is complete. This key elements allows you to keep going rather then getting kicked out of your app.

A category that further explains this code and a sample project is available here: http://www.raizlabs.com/dev/2014/04/getting-the-best-behavior-from-phone-call-requests-using-tel-in-an-ios-app/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM