Is it possible to determine if the SIM/Phone number has changed?
Asked Answered
R

1

13

We have a product where the user registers by providing their phone number.

However after they register they could potentially change their sim.

Is it possible to programatically determine if the sim has been removed or inserted?

(Thanks if you provide it, but any digression comments on the use of using the phone number in the first place would be irrelevant to this discussion, I don't want to discuss that aspect of things, only the sim aspect).

Requirement answered 3/6, 2012 at 16:44 Comment(0)
V
23

Yes, of course it is possible. Link CoreTelephony.framework to make following code compile:

CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier* carrier = info.subscriberCellularProvider;
NSString *mobileCountryCode = carrier.mobileCountryCode;
NSString *carrierName = carrier.carrierName;
NSString *isoCountryCode = carrier.isoCountryCode;
NSString *mobileNetworkCode = carrier.mobileNetworkCode;

// Try this to track CTCarrier changes 
info.subscriberCellularProviderDidUpdateNotifier = ^(CTCarrier* inCTCarrier) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"User did change SIM");
        });
};

By values of mobileCountryCode, mobileNetworkCode, carrierName, isoCountryCode you can judge about presence of SIM. (Without SIM they become incorrect).

There is also some undocumented functions/notifications in CoreTelephony, but your app may be banned by Apple if you'll use them. Anyway:

// Evaluates to @"kCTSIMSupportSIMStatusReady" when SIM is present amd ready; 
// there are some other values like @"kCTSIMSupportSIMStatusNotInserted"
NSString* CTSIMSupportGetSIMStatus(); 

// Use @"kCTSIMSupportSIMStatusChangeNotification" to track changes of SIM status:
[[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(SIMNotification:)
    name:@"kCTSIMSupportSIMStatusChangeNotification"
    object:nil
];

// This one copies current phone number
NSString* CTSettingCopyMyPhoneNumber()

Addendum Another possible (and legal) solution: if your company has a database of phone numbers, you can send an sms or call(and cut) any specific number to verify that user still uses the same phone number.

UPDATE Function NSString* CTSettingCopyMyPhoneNumber() doesn't work anymore (returns empty string).

Ventura answered 5/6, 2012 at 20:33 Comment(8)
That does not help much when he wants to find out if the user has changed SIM card. This class only returns information that by no means can separate two SIM cards. What if the user changed SIM card and phone number, but still use the same carrier?Guardroom
As Andreas says, by itself this [documented] API is not much use, however if it was possible to register for a notification of change of one of these values that would be useful. Even if the user takes out the sim and then puts the same one back in, if I knew that happened then its not too bad, even if I don't know that the sims were different or not. At least I would know that the sims could potentially be different. Thanks for the info on the undocumented API, maybe its possible to find out if its ok with apple to use this.Requirement
Andreas, Chris, I should state it clear: It's unable to obtain any valueable SIM information by any documented means for sure. We can only guess by iterpreting carrier information and cellular network availablity. If that's not enough for you then use undocumented features and hacks. There's a lot of them in iOS. But you may be banned from Appstore, and there's a reason for that. If someone will obtain such information from SIM like phone number or IMSI, there's a pleanty of posibilities to do a lot of bad things like mobile phone spam, eavesdropping etcVentura
Chris, didn't I answer your questions? Any other questions?Ventura
Important information missing: your app must be running when the change happens to detect it.Peruke
Solution with private API is not working on my side. Can you guide me what extra i have to do to make it functional. ThanxGush
Unfortunately the posted solution by Oleg Trakhman works only if the app is running.Bakker
Both the private API and the subscriberCellularProviderDidUpdateNotifier block are not working on iOS 9.2.1: when I pull out the sim card, nothing happens.Harty

© 2022 - 2024 — McMap. All rights reserved.