Hi, I have the same question, looking for a replacement for CTCarrier. I am using mobileNetworkCode as a way to see if the iDevice can actually perform a call at this moment, since an iPhone could also be used without a SIM-card installed. I am using code that I picked up as a gist on Github, see below (part of a SwiftUI View). If you would have another way to check call capability without using CTCarrier, I would be much obliged.
Button (action: {
// check if device can perform phone call
// https://gist.github.com/krin-san/8f34206bc0e7c9fddcc9
var isCapableToCall: Bool = false
guard let url = URL(string: "tel:"+item.telephone) else {return}
if UIApplication.shared.canOpenURL(url) {
// Check if iOS Device supports phone calls
// User will get an alert error when they will try to make a phone call in airplane mode
if let subscribers = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders {
for key in subscribers.keys {
if ((subscribers[key]?.mobileNetworkCode?.isEmpty) == nil) {
isCapableToCall = true
break
}
}
} else {
// Device cannot place a call at this time. SIM might be removed
isCapableToCall = false
}
} else {
// iOS Device is not capable for making calls
isCapableToCall = false
}
if isCapableToCall {
UIApplication.shared.open(url)
} else {
// if device cannot call, show a dialog with the phone number
showPhoneNumber.toggle()
}
}, label: {
VStack {
Image(systemName: "phone").font(.system(.title2))
Text(LocalizedStringKey("Call"))
.font(.caption2)
.padding(1)
}
.frame(width: 50, height: 45)
})
Post
Replies
Boosts
Views
Activity
So true. I guess I'm growing old. Since the datastore only provides actual phone numbers, I had not thought of a VoIP app. So for a more general case than mine, you're spot on. I have now filed a Suggestion to make canOpenURL smarter. That would be a good spot for getting my way of using CTCarrier covered in a future iOS. Bug/suggestion number FB11678610 .