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
Simply checking if a device "supports" phone calls might not be the best way to go about things depending on what your trying to accomplish. Believe it or not, some people use old iPhones without service as if they were an iPod Touch. Sometimes people don't have SIM cards installed in their iPhones. In my app I wanted to dial a phone number if the users device was able to, otherwise I wanted to display the phone number and prompt the user to grab a phone and dial it. Here is a solution I came up with that has worked so far. Feel free to comment and improve it.
// You must add the CoreTelephony.framework
#import
#import
-(bool)canDevicePlaceAPhoneCall {
/*
Returns YES if the device can place a phone call
*/
// Check if the device can place a phone call
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]) {
// Device supports phone calls, lets confirm it can place one right now
CTTelephonyNetworkInfo *netInfo = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mnc = [carrier mobileNetworkCode];
if (([mnc length] == 0) || ([mnc isEqualToString:@"65535"])) {
// Device cannot place a call at this time. SIM might be removed.
return NO;
} else {
// Device can place a phone call
return YES;
}
} else {
// Device does not support phone calls
return NO;
}
}
You'll notice I check if the mobileNetworkCode is 65535. In my testing, it appears that when you remove the SIM card, then the mobileNetworkCode is set to 65535. Not 100% sure why that is.