2

I'm trying to check if a device has cellular service available (not data) and if so then allow them to make a call. I'm currently using [[UIApplication sharedApplication] canOpenURL:numberURL] just to know if the device can make phone calls which will obviously return YES if it's an iPhone or other device as I read. Currently I'm testing on a device that has no carrier service. Any help on this would be greatly appreciated, thanks.

Josh Valdivieso
  • 1,168
  • 1
  • 14
  • 22
  • 1
    [this question](http://stackoverflow.com/questions/853467/retreiving-carrier-name-from-iphone-programmatically) may help – Daniel Feb 05 '15 at 15:28
  • Thanks, this gives me information about the carrier and other network statuses but I still can't seem to determine if a device has service or not. Even though my device says "No Service" the carrier and codes are all still available as it was in service before from AT&T. – Josh Valdivieso Feb 05 '15 at 16:56

3 Answers3

1

As far I know you can play with the info about the carrier of your phone with 'CoreTelephony' framework.

Check it out for yourself: https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternet/Reference/CoreTelephonyFrameworkReference/index.html#//apple_ref/doc/uid/TP40009603

https://developer.apple.com/library/prerelease/ios/samplecode/CoreTelephonyDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010746

EDIT:

https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternet/Reference/CTTelephonyNetworkInfo/index.html#//apple_ref/occ/instp/CTTelephonyNetworkInfo/subscriberCellularProvider

Try the class 'CTCarrier' and see if it solves your problem.

@property(readonly, retain) CTCarrier *subscriberCellularProvider

Discussion
A CTCarrier object that contains information about the user’s home cellular service provider—that is, the provider with whom the user has an account. This information is available immediately after you allocate and initialize the CTTelephonyNetworkInfo object.
santibernaldo
  • 825
  • 1
  • 11
  • 26
  • Right, but I can't seem to determine if the device has service or not within the API. I've tried many different approaches but all seem not to work... – Josh Valdivieso Feb 05 '15 at 16:58
  • `CTCarrier` doesn't return anything that I can find to be used towards detecting if the phone is in service or not. Like stated in my question I've had service before with this device and no longer have service so i'm not able to make calls and `subscriberCellularProvider` returns the same information as it would if the phone had cellular service. – Josh Valdivieso Feb 05 '15 at 19:41
0

You can check to see if device has a carrier with its sim card:

`CTTelephonyNetworkInfo telephonyNetworkInfo = [[CTTelephonyNetworkInfo alloc] init];

CTCarrier carrier = [telephonyNetworkInfo subscriberCellularProvider];`

check for any of the following properties on carrier to see if there is a carrier on phone:

carrier.carrierName carrier.carriermobileCountryCode carrier.mobileNetworkCode carrier.isoCountryCode

Mepla
  • 438
  • 4
  • 16
  • A device that contains a sim card without service (such as the device i'm using) retains all of the property values listed above from the lastly used carrier so this won't work for devices that still contain a sim card but have no service. – Josh Valdivieso Apr 07 '15 at 13:34
  • Then maybe you can use `CTGetSignalStrength`, This is actually not documented, but you can google it or use http://stackoverflow.com/questions/8254327/get-carrier-name-and-signal-strength-return-wrong-value-in-iphone or http://stackoverflow.com/questions/15427507/how-to-find-out-carrier-signal-strength-programatically – Mepla Apr 08 '15 at 04:48
  • Is the `CTGetSignalStrength` something that's accepted by the app store? – Josh Valdivieso Apr 10 '15 at 15:15
  • Well, I don't know exactly how that may turn out, but since there is no official documentation for it and there is rule regarding "not using hidden APIs" in appstore review guidelines, It may be rejected by them. Best shot is reading about people who used it. – Mepla Apr 11 '15 at 05:25
-1

You're probably looking for something like Reachability. You can use this class to determine connectivity to the network and the means by which the device is connected, either ReachableViaWiFi or ReachableViaWWAN.

There is one caveat when dealing with Reachability that you should be aware of before using it. Sometimes reachability will report that there is no connection but a connection could in fact be established if a request were attempted. The best use of Reachability is after a request has failed, when the device can be sure that it can't make a connection and you can report that to the user.

Patrick Goley
  • 5,397
  • 22
  • 42