Created
November 9, 2015 12:39
-
-
Save krin-san/8f34206bc0e7c9fddcc9 to your computer and use it in GitHub Desktop.
Check if iOS device is capable to call / send SMS message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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