Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否可以确定SIM/电话号码是否已更改?_Ios_Sim Card_Core Telephony - Fatal编程技术网

Ios 是否可以确定SIM/电话号码是否已更改?

Ios 是否可以确定SIM/电话号码是否已更改?,ios,sim-card,core-telephony,Ios,Sim Card,Core Telephony,我们有一种产品,用户通过提供电话号码进行注册 然而,在他们注册之后,他们可能会改变他们的sim卡 是否可以通过编程确定sim卡是否已拔出或插入 (如果您能提供,我将不胜感激,但任何关于使用电话号码的离题评论都与本次讨论无关,我不想讨论这方面的问题,只想讨论sim卡方面的问题)。是的,当然可以。链接corethelphony.framework以编译以下代码: CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];

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

然而,在他们注册之后,他们可能会改变他们的sim卡

是否可以通过编程确定sim卡是否已拔出或插入


(如果您能提供,我将不胜感激,但任何关于使用电话号码的离题评论都与本次讨论无关,我不想讨论这方面的问题,只想讨论sim卡方面的问题)。

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

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卡,它们将变得不正确)

CoreTelephony中也有一些未记录的功能/通知,但如果您使用它们,您的应用程序可能会被苹果公司禁止。无论如何:

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

附录另一种可能的(合法的)解决方案:如果您的公司有电话号码数据库,您可以发送短信或拨打(并切断)任何特定号码,以验证用户是否仍然使用相同的电话号码


更新函数
NSString*CTSettingCopyMyPhoneNumber()
不再工作(返回空字符串)。

当他想知道用户是否更换了SIM卡时,这没有多大帮助。此类仅返回绝对不能分隔两张SIM卡的信息。如果用户更改了SIM卡和电话号码,但仍然使用同一个运营商,该怎么办?正如Andreas所说,这个(记录在案的)API本身没有多大用处,但是如果可以注册一个有用的更改这些值之一的通知的话。即使用户取出sim卡,然后将相同的sim卡放回,如果我知道发生了这种情况,那也不算太糟糕,即使我不知道sim卡是否不同。至少我知道模拟人生可能会有所不同。感谢您提供的关于未记录API的信息,也许可以了解苹果是否同意使用此API。Andreas,Chris,我应该明确指出:它无法通过任何记录手段获得任何有价值的SIM卡信息。我们只能通过预测载波信息和蜂窝网络的可用性来猜测。如果这对你来说还不够,那么就使用未记录的特性和黑客。iOS中有很多。但是你可能被禁止进入Appstore,这是有原因的。如果有人会从SIM卡(如手机号码或IMSI)上获取此类信息,那么有很多可能会做很多坏事,比如手机垃圾邮件,窃听Etcu幸运的是,Oleg Trakhman发布的解决方案只有在应用程序正在运行时才起作用。私有API和subscriberCellularProviderDidUpdateNotifier块在iOS 9.2.1上都不起作用:当我拔出sim卡时,什么都没有发生。