Skip to content

Instantly share code, notes, and snippets.

@numanayhan
Forked from krin-san/CoreTelephonyCheck.swift
Created October 29, 2022 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numanayhan/9c0bdf00636a5d9f78bba6d5f1700a65 to your computer and use it in GitHub Desktop.
Save numanayhan/9c0bdf00636a5d9f78bba6d5f1700a65 to your computer and use it in GitHub Desktop.
Check if iOS device is capable to call / send SMS message
// Swift version of the code from http://stackoverflow.com/a/30335594/1986600
import CoreTelephony
override func awakeFromNib() {
super.awakeFromNib()
let isCapableToCall: Bool
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "tel://")!) {
// Check if iOS Device supports phone calls
// User will get an alert error when they will try to make a phone call in airplane mode
if let mnc = CTTelephonyNetworkInfo().subscriberCellularProvider?.mobileNetworkCode where !mnc.isEmpty {
// iOS Device is capable for making calls
isCapableToCall = true
} else {
// Device cannot place a call at this time. SIM might be removed
isCapableToCall = false
}
} else {
// iOS Device is not capable for making calls
isCapableToCall = false
}
// Do something with isCapableToCall
let isCapableToSMS: Bool
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "sms:")!) {
isCapableToSMS = true
} else {
isCapableToSMS = false
}
// Do something with isCapableToSMS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment