2011-01-03 32 views
11

Tôi cần gọi chương trình trong ứng dụng của mình bằng cách nhấp vào nút.Làm thế nào để thực hiện cuộc gọi theo chương trình?

cho mã tôi tìm thấy như thế này.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:1-800-555-1212"]]; 

là nó hoạt động trong iphone sdk 3.0 và iphone 2.0 cũng

bất kỳ pls có thể giúp

Thank u trước.

Trả lời

48

Giữ số điện thoại trong một chuỗi riêng biệt.

NSString *phoneNumber = @"1-800-555-1212"; // dynamically assigned 
NSString *phoneURLString = [NSString stringWithFormat:@"tel:%@", phoneNumber]; 
NSURL *phoneURL = [NSURL URLWithString:phoneURLString]; 
[[UIApplication sharedApplication] openURL:phoneURL]; 
+0

là nó hoạt động trong 3.0.2.0 os – MaheshBabu

+0

@MaheshBabu: Xin lỗi người đàn ông .. Không có ý tưởng .. Nhưng tôi đoán nó hoạt động .. – EmptyStack

+0

Điều này chỉ hoạt động trên iPhone. 3,2 sẽ là iPad, vì vậy về mặt kỹ thuật, nó sẽ không hoạt động trên 3.2. – WrightsCS

1
NSLog(@"Phone calling..."); 

     UIDevice *device = [UIDevice currentDevice]; 

     NSString *cellNameStr = [NSString stringWithFormat:@"%@",self.tableCellNames[indexPath.row]]; 

     if ([[device model] isEqualToString:@"iPhone"]) { 

      NSString *phoneNumber = [@"tel://" stringByAppendingString:cellNameStr]; 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 

     } else { 

      UIAlertView *warning =[[UIAlertView alloc] initWithTitle:@"Note" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

      [warning show]; 
     } 

// VKJ

0

Các kiểm tra đoạn mã sau đây nếu thẻ SIM có mặt hay không cũng như nếu các thiết bị có khả năng thực hiện cuộc gọi như các thiết bị ios phi sim

#import <CoreTelephony/CTTelephonyNetworkInfo.h> 
#import <CoreTelephony/CTCarrier.h> 


    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. 
    } 

Đừng quên để thêm khung CoreTelephony

Credit

Các vấn đề liên quan