Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

ios - Is it possible to determine if the SIM/Phone number has changed?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...