Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a call programmatically?

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

for that i found code like this.

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

Is it work in iphone sdk 3.0 and iphone 2.0 also

Can any pls help

Thank u in advance.

like image 662
Mahesh Babu Avatar asked Jan 03 '11 05:01

Mahesh Babu


2 Answers

Keep the phone number in a separate string.

NSString *phoneNumber = @"1-800-555-1212"; // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:@"tel:%@", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
like image 89
EmptyStack Avatar answered Sep 21 '22 20:09

EmptyStack


  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

like image 28
Vinod Joshi Avatar answered Sep 21 '22 20:09

Vinod Joshi