Is there any way to determine if the iphone is roaming?
Asked Answered
R

3

22

I am working on an iPhone application and would really like to determine if the device is roaming so that I can intelligently avoid costing my users expensive connections if out of their home network.

The application I am writing is for jailbroken phones, however I would prefer to use standard SDKs if possible.

Here is what I've already found:

1. Apple SDKs: In the apple documentation, I found the promise in Apple's SCNetworkReachability API. The API provides access to such things as whether you are on a WIFI or a cell phone network, whether a network connection is currently established, etc. However searching the SCNetworkReachability API reference pdf for 'roam' or 'roaming' both turn up nil. So does their sample code.

2. Grep of a Jailbroken iPhone FS: The preferences -> general -> networking tab is where users can turn on or off their roaming. Looking in the plist file for this ("/Applications/Preferences/Network.plist") I was able to find the following references:

        PostNotification = "com.apple.commcenter.InternationalRoamingEDGE.changed";
        cell = PSSwitchCell;
        default = 1;
        defaults = "com.apple.commcenter";
        key = InternationalRoamingEDGE;
        label = "EDGE_ROAMING_TOGGLE";
        requiredCapabilities =             (
            telephony
        );

This is certainly a lead, as it appears I can sign up for notifications that the user has changed the InternationalRoaming settings. Still, I'm not certain how to turn this into the knowledge that they are in fact, presently roaming.

3. Check the class dumped sources of SpringBoard: I've dumped the classes of SpringBoard using class-dump. I was unable to find any references to 'roam' or 'roaming'

4. Obviously I started by checking at SO for this: Couldn't find anything related.

Further steps: Does anyone have any advice here? I know this is possible. Apple clearly has made it very difficult to find however. I highly doubt this is possible without using a private framework. (such as CoreTelephony). As this is a jailbroken app, I may resort to screen-scraping the the carrier name with injected code in the SpringBoard, but I would really rather prefer not to go that route. Any advice much appreciated. Thanks.

Reconcile answered 23/5, 2009 at 0:39 Comment(1)
You might try the Apple Developer Forums.Cotterell
R
24

There is! It's not documented at all, and I highly doubt this would work on a non-jailbroken phone (as it requires using files not in the sandbox). However, here is how it is done.

The iPhone file system keeps two softlinks:

static NSString *carrierPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.carrier.plist";
static NSString *operatorPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.operator.plist";

when these links are pointing at the same file, the telephone is not roaming. When pointing at different files, the telephone is romaing.

Simplified code (no error checking, etc):

- (BOOL)isRoaming
{
    NSFileManager *fm = [NSFileManager defaultManager];
    NSError *error;
    NSString *carrierPListPath = [fm destinationOfSymbolicLinkAtPath:carrierPListSymLinkPath error:&error];
    NSString *operatorPListPath = [fm destinationOfSymbolicLinkAtPath:operatorPListSymLinkPath error:&error];
    return (![operatorPListPath isEqualToString:carrierPListPath]);
}
Reconcile answered 8/6, 2009 at 19:45 Comment(7)
Yes. I wouldn't have written it down for you if it didn't work for me. I was on a jailbroken system however. As mentioned, doubt it would work in regular iphone program.Reconcile
I tried it on regular iphone, and it works without error. I wasn't in roaming and operator and carrier path were the same.Evonevonne
com.apple.operator.plist does not seem to be accessible any more (from iOS 6.1 onwards)Fay
It works on non-jailbreak device. Tested on iphone 5, ios 7.1Schmid
Will the app store allow this? They have a rule about reading and writing files outside the sandbox, but we aren't actually reading or writing anything here -- just getting the name of a file. Anyone know what Apple would say? (I've asked this on their forums with no response)Sapling
The code works in iOS10. If no roaming the operatorPlistPath is null. I prefer to change the last line to ![carrierPListPath isEqualToString:operatorPListPath] as carrierPListPath will never be nullCrystallize
@iluvatar_GR: calling a method on nil will always return 0, so it will still be right in this caseOxcart
S
1

the solution of the symlinks are not the only way to do it but definitely it is the best. As I just realized, the Strings returned contains the MCC and MNC codes of the operator and carrier!!! Even the core telephony framework is not able to retrieve those informations about the operator your iPhone is attached when in roaming.

 Logs: 
 carrier: /System/Library/Carrier Bundles/iPhone/72410/carrier.plist
 operator: /System/Library/Carrier Bundles/iPhone/20810/carrier.plist

As you can see, the carrier (original cellular provider) line contains the file inside the "folder" 72410, which means MCC 724 (Brazil) and MNC 10 (VIVO). The operator (actually the one my cell phone is attached now - i'm in roaming) is inside the folder 20810, which means MCC 208 (France) and MNC 10 (SFR).

By the way, I'm using iPhone 4 with iOS5.

Sacker answered 12/11, 2011 at 9:51 Comment(1)
"the solution of the symlinks are not the only way to do it but definitely it is the best". What are the other solutions that comes to your mind ? I'm interested in another one but I can't find any.Macula
A
0

On a non-jailbreak device 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, and 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.

Abuttal answered 9/8, 2014 at 19:11 Comment(3)
This is not working as expected when my device is connected to wifi.Acrimonious
Yes, when you're on wifi you'll get the details for the wifi connection rather than carrier. You can detect if you're on wifi or not using iOS APIs though, and even when you are knowing that you're in a different country might be useful.Abuttal
You'll get the IP of your HOME mobile operator on roaming (that's the way the network designed)Intelligentsia

© 2022 - 2024 — McMap. All rights reserved.