是否可以确定SIM/电话号码是否已更改? [英] Is it possible to determine if the SIM/Phone number has changed?

查看:215
本文介绍了是否可以确定SIM/电话号码是否已更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一种产品,用户可以通过提供其电话号码进行注册.

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

但是,他们注册后可能会更改他们的SIM卡.

However after they register they could potentially change their sim.

是否可以通过编程方式确定是否已删除或插入了sim卡?

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

(感谢您提供,但是首先涉及使用电话号码的任何题外话都与本次讨论无关,我不想讨论该方面的内容,仅讨论sim方面的内容)

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

推荐答案

是的,当然可以.链接CoreTelephony.framework以使以下代码编译:

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");
        });
};

通过mobileCountryCode,mobileNetworkCode,carrierName,isoCountryCode的值,您可以判断是否存在SIM. (没有SIM卡,它们将变得不正确).

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

CoreTelephony中还有一些未记录的功能/通知,但是如果您使用它们,Apple可能会禁止您的应用程序.无论如何:

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
];

//这将复制当前电话号码
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.

更新函数NSString* CTSettingCopyMyPhoneNumber()不再起作用(返回空字符串).

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

这篇关于是否可以确定SIM/电话号码是否已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆