Detecting whether or not device support phone calls?

后端 未结 9 2160
别跟我提以往
别跟我提以往 2020-11-28 23:13

Is the below code reliable to be used to determine whether a device can support phone calls or not? My concern is if apple changes the iphone string to anything else let\'s

9条回答
  •  一整个雨季
    2020-11-29 00:01

    Based on @TheGuardian's answer, I think this might be a simpler approach:

       private final func canMakePhoneCall() -> Bool {
           guard UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone else {
            return false
           }
    
           let mobileNetworkCode = CTTelephonyNetworkInfo().subscriberCellularProvider?.mobileNetworkCode
           let isInvalidNetworkCode = mobileNetworkCode == nil || mobileNetworkCode?.characters.count <= 0
                                                            || mobileNetworkCode == "65535"
                                                            //When sim card is removed, the Code is 65535
    
           return !isInvalidNetworkCode
        }
    

提交回复
热议问题