Failed to call

I want to make a phone call, and for this I use the code below.

- (void)callPhoneNumber:(NSString *)phoneNumber
{
    UIWebView * webView2 = [[UIWebView alloc] init];

    // Remove non-digits from phone number
    phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];

    // Make a call
    NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phoneNumber]];
    [webView2 loadRequest:[NSURLRequest requestWithURL:url]];
    [self.view addSubview:webView2];
}

Before calling, I will ask the user to select an option using UIActionSheet. When the user selects a parameter, based on which I place a call.

The problem is that the above code works fine if I don't show UIActionSheetand place the call directly. It asks for a warning requesting user confirmation for making a call. But after displaying UIActionSheet, if I call the method above, it does not display confirmation confirmation.

, , Xcode, , . . , ?

- ? ?

EDIT: . . , - , . , .

NSString *phoneNumberURL = [NSString  stringWithFormat:@"telprompt:%@", phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberURL]];

: .

. . , .

# pragma mark - ALERT VIEW DELEGATE

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == MY_TAG)
    {
        // Ask to select option
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Option" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Option1", @"Option2", nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
        [actionSheet showInView:self.view];   
    }
}


#pragma mark - UIActionSheet Methods

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // If not pressed cancel button.i.e. selected one of the options
    if (buttonIndex != actionSheet.cancelButtonIndex)
    {
        // Place a call
        [self callPhoneNumber:@"1234567890"];
    }
}
+4
6

, , , tel: telprompt: tel:// telprompt:// //.

, - , , .

- (void)callPhoneNumber:(NSString *)phoneNumber
{
    // If statement to check we actually have something
    if(phoneNumber) {
        // Remove any unwanted whitespace, if there is any whitespace it will not work
        phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
        // Create an NSURL instance of your number
        // Note the extra `//` in the string
        // Also note you can also use: `telprompt://` instead of `tel://`
        NSURL *urlPhoneNumber = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", phoneNumber]];
        // Check to make sure we can open this because iPad and iPod will not respond to phone calls
        if([[UIApplication sharedApplication] canOpenURL:urlPhoneNumber]) {
            // If we can (So if iPhone really) make the call.
            [[UIApplication sharedApplication] openURL:urlPhoneNumber];
        }
    }
}

Apple

, Apple Documentation , tel: telprompt: , //, , - //. tel: telprompt: URL Schemes, // "URL-". iPhone Development 101

+1

OpenURL URL.

- (void)callPhoneNumber:(NSString *)phoneNumber
{
    // Remove non-digits from phone number
    phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];

    // Make a call
    NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phoneNumber]];
    [[UIApplication sharedApplication] openURL:url];
}
0

UIWebView :

NSURL *phoneUrl = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt:%@",phoneNumber]];

if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
    [[UIApplication sharedApplication] openURL:phoneUrl];
}

: , , . , :

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
         //Code for cancel button
    }
    if (buttonIndex == 1)
    {
       //Code for calling phone call
       [self callPhoneNumber:@"1234567890"];
    }
}

2:

:

  - (void)checkCallAlert :(NSInteger)index
 {
    UIAlertView *checkCallAlert = [[UIAlertView alloc] initWithTitle:@"Check?" message:@"Are you sure you want to continue?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
    [checkCallAlert setTag:index];
    [checkCallAlert show];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
         //Code for cancel button
    }
    if (buttonIndex == 1)
    {

       [self checkCallAlert : buttonIndex];


    }

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if(alertView.tag == 1){
   //Destination 1 clicked
    //Code for calling phone call
       [self callPhoneNumber:@"1234567890"];
}
}

.

0

[self callPhoneNumber ... ] callPhoneNumber :

[self performSelector:@selector(callPhoneNumber:) withObject:@"1234567890" afterDelay:0];

UIActionSheet :

iOS 4.0 ,

, applicationWillResignActive, actionSheet .

0
NSString * telephoneNumber;

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneNumber]];

[telephoneNumber release];
0

didDismissWithButtonIndex:, UIActionSheet , , - .

0

Source: https://habr.com/ru/post/1539750/


All Articles