Umang
Umang

Reputation: 139

How to call a number on a button click in iphone development

I am trying to create an application in which I want to call a specific number on button click...
Button is having a title "Call xxx-yyy-zzzz for help", after clicking this button call menu will appear with this number dialed and I can either place a call or reject.

Upvotes: 0

Views: 6557

Answers (3)

Here's how to initiate a call:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:yourtelephonenumber"]];

This thread also has some answers.

Upvotes: 1

KingofBliss
KingofBliss

Reputation: 15115

Use UIAlertView to implement this, code as follows,

-(IBAction)buttonAction
{
   UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"Call xxx-yyy-zzzz?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",nil];
    [alert show];
    [alert release];
}

//AlertView delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 if(buttonIndex==1)
   {
     [[UIApplication sharedApplication] 
    openURL:[NSURL URLWithString:@"tel://xxx-yyy-zzzz"]];   
   }
   else
   {
    //Do whatever you want
   }
}

Upvotes: 0

Chris
Chris

Reputation: 8034

[[UIApplication sharedApplication] 
    openURL:[NSURL URLWithString:@"tel://xxx-yyy-zzzz"]];

Upvotes: 4

Related Questions