Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: phone number dialing not working

Tags:

ios

I'm building an app that lets you call different service centers from Netherlands. The problem is that some of them have a different commercial format (like 0800-xxxx) and the device can't make the call. The code looks like this:

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

Do you have any idea how to format the number or to make the phone call, no matter it's format?

EDIT: This is how the phoneNumber is created:

NSString *phoneNumberString = phoneNumber; // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", phoneNumberString];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
like image 729
Andra Todorescu Avatar asked Sep 06 '12 09:09

Andra Todorescu


People also ask

Why can't I dial numbers on my iPhone?

Turn Airplane Mode on and off. Go to Settings and turn on Airplane Mode, wait five seconds, then turn it off. Check Do Not Disturb. Go to Settings > Focus > Do Not Disturb and make sure it's off.

Why won't my phone Let me dial a number?

Check that Airplane Mode is disabled on your device. If it is disabled but your Android phone still can't make or receive calls, try enabling Airplane Mode and disable it after a couple of seconds. Disable Airplane Mode from Android Quick Settings drawer or navigate to Settings > Network & Internet > Airplane Mode.

When I try to make a call on my iPhone it says call failed?

If you see a Call Failed message when trying to place a call, the problem could be with your cellular provider or your iPhone. To troubleshoot your iPhone, you can toggle Airplane mode, restart your phone, and reset your SIM card.


1 Answers

I used this code and it worked:

NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", escapedPhoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];

if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
    [[UIApplication sharedApplication] openURL:phoneURL];
}
like image 157
Andra Todorescu Avatar answered Oct 18 '22 20:10

Andra Todorescu