I wrote some code to initiate phone call from String like the attached image. [function: phoneCallInitiation][1]
Some phone number can be initiated well with the format such as 02-123-1234, but some phone number with 031-123-1234 cannot be initiated but I can see phoneNumberString is working well.
Can u guess any reason to work like this?
func callButtonPressed () {
let alertViewController = UIAlertController(title: NSLocalizedString("Call", comment: ""), message: "\(storeToDisplay.phoneNumber!)", preferredStyle: .alert)
alertViewController.addAction(UIAlertAction(title: "Call", style: .default, handler: { (alertAction) -> Void in
let phoneNumberString = "tel://\(self.storeToDisplay.phoneNumber!)"
print("This is phonenumber: \(phoneNumberString)")
if let url = URL(string: phoneNumberString) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
print("WHAT Happenes")
}
}))
alertViewController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (alertAction) -> Void in
alertViewController.dismiss(animated: true, completion: nil)
}))
present(alertViewController, animated: true, completion: nil)
}