Possible way to detect sim card detection in ios?

前端 未结 6 1867
野趣味
野趣味 2020-12-31 20:33

I have a iphone app that has the capability to send messages. I want to alert user when sim card is not available in iphone. So i tried below three function to check sim car

6条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 20:49

    Complementing the Anneq Anwar answer, here the swift version:

    import CoreTelephony
    func isSimAvailable()  -> Bool {
        var isSimCardAvailable = true
        var info = CTTelephonyNetworkInfo()
        var carrier = info.subscriberCellularProvider
        if carrier != nil && carrier.mobileNetworkCode == nil || carrier.mobileNetworkCode.isEqual("") {
            isSimCardAvailable = false
        }
        return isSimCardAvailable
    }
    

    fix: The carrier can be nil in some devices

提交回复
热议问题