How to get roaming status in IOS

8.4k Views Asked by At

I want to get notified when I enter in roaming area in my iOS app, I have already read the documentation for NSLocale , SCNetworkReachability , and core telephony (I may have missed something). I need to get this info from sim (or any other way if possible).

3

There are 3 best solutions below

1
On

There's no iOS API for detecting roaming status, but you can use third party services like http://ipinfo.io (my own service) to find out the current country of even carrier code based on the device's IP address. You can then compare that to the CTCarrier details to determine if the device is roaming. Here's the standard ipinfo.io API response:

$ curl ipinfo.io/24.32.148.1 
{
    "ip": "24.32.148.1",
    "hostname": "doc-24-32-148-1.pecos.tx.cebridge.net",
    "city": "Pecos",
    "region": "Texas",
    "country": "US",
    "loc": "31.3086,-103.5892",
    "org": "AS7018 AT&T Services, Inc.",
    "postal": "79772"
}

Custom packages are available that also include the mnc/mcc details of mobile IPs though. See http://ipinfo.io/developers for details.

2
On

The usual method would be to get the carrier's country code from the core telephony interface and then compare that with the country code from reverse geocoding the location.

Advantages: works with VPNs and when the user has disabled data when roaming. Disadvantages: doesn't work without location.

I don't have any non-copyright code for you, but the key you need in the place marks dictionary you need for country code is @"CountryCode" Geocoding would be something like:-

CLGeocoder* geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler: ^(NSArray* placemarks){}]

The country code for the provider would be

NSString* homeCountry = [netInfo.subscriberCellularProvider isoCountryCode];

Hope this helps

0
On

We used to have the same problem before on iOS and we ended up building a dedicated API for it. It works by comparing the IP Geolocation (based on IP address of the requester party) of the device against it's GPS position provided. If the user is detected as being physically outside of the country determined by their IP address, then they are deemed to be roaming.

We decided to offer this API for free and unlimited, no restrictions, no throttling. No credit card, not even account required, just run a simple query:

curl -X GET --header 'Accept: application/json' 'https://api.bigdatacloud.net/data/am-i-roaming?latitude=[your latitude]&longitude=[your longitude]'  

the response is very simple, just a true or false:

{
"isRoaming": true
}

It's very fast too! Our servers usually respond in under 1 millisecond time.

This API can obviously give a false positive results if executed via VPN/proxy or a non cellular interface, therefore it would be suggested to make sure you're using cellular interface when making the call.

Enjoy!