2

I am doing a birthday Remainder application . In that i provided a textfield to enter a mobile /phone number. And bottom i provided a button in which if we press that button call need to be proceed to the number given in the text field.I tried but i am not able to do that.Can any one help me in coding.Thanks!

3 Answers3

1

Try This One.

-(void) makeCall{
 NSString* phoneNumber=yourTextFiled.text;//TextFiled 
 NSString *phoneNumber = [NSString stringWithFormat:@"%@",phoneNumber];
 NSURL* callUrl=[NSURL URLWithString:[NSString   stringWithFormat:@"tel:%@",phoneNumber];
 //check  Call Function available only in iphone
 if([[UIApplication sharedApplication] canOpenURL:callUrl]){

[[UIApplication sharedApplication] openURL:callUrl]];
 }
 else{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"ALERT" message:@"This function is only available on the iPhone"  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alert show];
[alert release];
}    
}

I hope,it'll Really helpful to you.

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
  • You should not check if de device is an iPhone. You can just call `[[UIApplication sharedApplication] canOpenURL:]` method. If you call this method with a phonenumber URL it will return `NO` on devices that can't make calls. – rckoenes Mar 05 '12 at 08:16
  • @rckoenes yes you are right,but let me know if I follow that way(Check device and show alert according to the device).will it be wrong..? – Kamar Shad Mar 05 '12 at 08:32
  • 1
    Could be if Apple changes the device name or does not return the device name. But what if there is going to be an iPad that can make calls? – rckoenes Mar 05 '12 at 08:55
1

try this

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",self._phoneNumber]];
    [[UIApplication sharedApplication] openURL:url];    

works only in iphone, must be implemented your own alert delegate methods.

vishy
  • 3,241
  • 1
  • 20
  • 25
0

Pls check this 2 link:

calling number: Programmatically Dial a Phone number and pass DTMF using the iPhone SDK

and why not getting value from textfield: iPhone SDK: how to get the value of a UITextField in an alert?

Community
  • 1
  • 1