iOS app converting the dialed number automatically

  • 1
  • Question
  • Updated 3 years ago
  • Answered

I am working on an iOS app and  writing code to make calls from that app. It is working fine for non toll free numbers, But for some number such as 18601231000 for BigBasket, it is converting the number as +1(860)1231000 which when dialed comes as wrong number. But for numbers starting with 1800 it is working fine. I am searching solution of this query and taking help from some iphone developer forum and iphone blogs. If you have answer of my query please reply me. Please check my code snippet.


private func dialNumber(phoneNumber:String) {

let phoneUrl:NSURL = NSURL(string: "te

l://\(phoneNumber)")!

let application:UIApplication = UIApplication.sharedApplication()

if(application.canOpenURL(phoneUrl))

{

application.openU

RL(phoneUr

l)

}

self.ratingLabel.text = "Rate (self.selectedProvider!.providerName)' Customer Care"

callCenter.callEventHandler = {(call:CTCall!) in

switch call.callState {

case CTCallStateConnected:

break

case CTCallStateDisconnected:

NSUserDefaults.standardUserDefaults().setBool(true, forKey: "ctCall")

break

default:

break

}

}

}



Photo of FindNerd !

FindNerd !

  • 70 Points

Posted 3 years ago

  • 1
Photo of Arnold J

Arnold J

  • 3,142 Points 3k badge 2x thumb
Hi FindNerd,

This is not a questions we would normally help with, but I have a programming background, so maybe I can help.

While I don't program xcode or swift specifically, I think i know what the problem may be.  The phone number you are trying to call 18601231000 is in India (it is not a North American Toll Free number), and can't be called directly without first dialing the country codes.  What I think is happening is that the iOS is using the localization format for the phone number see it as a standard North American 1+10 digit number and is dialing it as such.  If you try dialing that number for any phone it will fail.

It is no different than going to BigBasket's website on your phone's browser and clicking on the phone number, it will simply try to dial the numbers exactly as they are referenced in the phone number link.

What you will likely need to do is write a function to determine if the number should use the local format, or if it is an International call.  If it is International and not formatted as such, append the phone number to the correct format before dialing.

a website like https://countrycode.org/how-to-call can help you determine the correct format for the call.  I would bet someone has written a code snippet that does this already.

Anyway, I hope this at least points you in the right direction.

AJ
(Edited)