Sim card change detection in iOS

2019-07-10 16:11发布

Somebody please help with the code for sim card detection change in iOS on Swift.

We have an app that lets users authenticate with phone number and we want to detect when user changes his sim(if app is in background) and show alert asking if he wants to authenticate with new number. Basically we want to detect the carrier change of the phone.

In my Appdelegate (DidFinishLaunching method):-

    let info = CTTelephonyNetworkInfo()
    if let cellularProvider  = CTTelephonyNetworkInfo().subscriberCellularProviderDidUpdateNotifier {
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            print("Notify sim change")

        })
    }

This is not detecting sim card change. What am I doing wrong? Please guide.

Thanks In Advance,

1条回答
一纸荒年 Trace。
2楼-- · 2019-07-10 17:01

In app terminate: check APNS devicetoken. If simcard changes then devicetoken changes too. Check with before devicetoken. When as app is running: Use CTTelephonyNetworkInfo().subscriberCellularProviderDidUpdateNotifier.

查看更多
登录 后发表回答