Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get roaming status in IOS

Tags:

ios

roaming

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).

like image 227
Rana Avatar asked Jul 17 '13 06:07

Rana


2 Answers

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

like image 163
Gordon Dove Avatar answered Nov 03 '22 07:11

Gordon Dove


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.

like image 38
Ben Dowling Avatar answered Nov 03 '22 09:11

Ben Dowling