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

前端 未结 1 1008
北荒
北荒 2020-12-08 12:21

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 possib

相关标签:
1条回答
  • 2020-12-08 12:34

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

    0 讨论(0)
提交回复
热议问题