Is the below code reliable to be used to determine whether a device can support phone calls or not? My concern is if apple changes the iphone string to anything else let\'s
This UIApplication.shared.openURL((URL(string: "tel://\(phoneNumber)")!)) will not say if it has SIM or Not this will just say, if the device has options to make a call. For example : A iPhone with or without SIM it'll return true, but in iPod Touch it will always return false, like wise if an ipad doesn't have sim option it will return false.
Here is the code that checks everything comprehensively ! (Using Swift 3.0)
if UIApplication.shared.canOpenURL(URL(string: "tel://\(phoneNumber)")!) {
var networkInfo = CTTelephonyNetworkInfo()
var carrier: CTCarrier? = networkInfo.subscriberCellularProvider
var code: String? = carrier?.mobileNetworkCode
if (code != nil) {
UIApplication.shared.openURL((URL(string: "tel://\(phoneNumber)")!))
}
else {
var alert = UIAlertView(title: "Alert", message: "No SIM Inserted", delegate: nil, cancelButtonTitle: "ok", otherButtonTitles: "")
alert.show()
}
}
else {
var alert = UIAlertView(title: "Alert", message: "Device does not support phone calls.", delegate: nil, cancelButtonTitle: "ok", otherButtonTitles: "")
alert.show()
}
By this way, we can make sure, device supports calling or not.