I want to make a phone call and I use below code for that.
- (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 making a call I ask user to choose an option using UIActionSheet
. When user selects an option, based on that I place a call.
Issue is that above code works fine if I don't display UIActionSheet
and directly place a call. It prompts an alert asking user's confirmation to make a call. But after displaying UIActionSheet
if I call above method then it does not display confirmation alert.
Weird thing is that after this if I stop app from Xcode, then app is put ion background as it should. But also I see that confirmation alert on device's home screen. How it is displayed on device's home screen and not in app?
Has anyone faced it before? What can be the reason?
EDIT : I also tried below code. But it has same issue. Whenever above webview code works below code also works. Same for when it does not work.
NSString *phoneNumberURL = [NSString stringWithFormat:@"telprompt:%@", phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberURL]];
Edit : Adding code for action sheet and delegate.
I first display an alert. On pressing alert button I display action sheet. And choosing option from action sheet I place a call.
# 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"];
}
}