Skip to content

Instantly share code, notes, and snippets.

@krin-san
Created November 9, 2015 12:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krin-san/8f34206bc0e7c9fddcc9 to your computer and use it in GitHub Desktop.
Save krin-san/8f34206bc0e7c9fddcc9 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