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).
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With