How to get roaming status in IOS
Asked Answered
C

3

6

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

Cogitable answered 17/7, 2013 at 6:36 Comment(4)
check this two question #901047 and #12473990Gerund
plz share the code...waht have you tried so farLoveinamist
so far, i have tried by tracking ip address and then calling a web service which can give me the location of that ip, but i am not suppose to use web service. I can use Mobile country code from core telephony to compare country code. 2) second restriction is that , we have to rely on SIM for this info, means some how get info from simCogitable
@Nitin Gohel - i have already tried codes from those links but 1.) we are not working for jailbreak versions 2) We are not supposed to call web services. 3) Can't work with ip addresses. 4) Only public APIsCogitable
E
2

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

Ectropion answered 2/10, 2014 at 10:13 Comment(2)
but, when i'm abroad, the isoCountryCode is still the same as the reversed geocodelocation countrycode... so for example if I go to Germany, CoreTelephony returns "de", and my reverseGeoCodeLocation also returns "de", therefore i am not roaming ?Afrikah
This doesn't necessarily work when the user is roaming in his own country. This can happen when near the border and the signal from the cell on the other side of the border is stronger than in the home country. It's a border case, but should be considered.Telega
A
1

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.

Allina answered 9/8, 2014 at 3:43 Comment(1)
This'll only work when connecting over the cellular network, without VPN. You can detect if the user is on wifi/cellular using iOS APIs though, and the ipinfo.io response will also indicate if it's a cellular connection or not.Allina
L
0

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!

Longhair answered 17/9, 2019 at 1:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.