How to make a call programmatically?

前端 未结 3 1516
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 20:16

I need to call programmatically in my app in a button click.

for that i found code like this.

[[UIApplication sharedApplication] openURL:[NSURL URLWi         


        
3条回答
  •  日久生厌
    2020-11-27 21:18

    The following code snippet checks if SIM card is present or not as well if the device is capable of making the call such as non-sim ios devices

     #import 
     #import 
    
    
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]]) {
            // Check if iOS Device supports phone calls
            CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
            CTCarrier *carrier = [netInfo subscriberCellularProvider];
            NSString *mnc = [carrier mobileNetworkCode];
            // User will get an alert error when they will try to make a phone call in airplane mode.
            if (([mnc length] == 0)) {
                // Device cannot place a call at this time.  SIM might be removed.
            } else {
                // iOS Device is capable for making calls
            }
        } else {
            // iOS Device is not capable for making calls
        }
    
    
    
        if ( ! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"sms:"]]) {
           // iOS Device is not capable to send SMS messages. 
        }
    

    Don't forget to add the CoreTelephony framework

    Credit

提交回复
热议问题