0

I have a UIButton with a telephone number as a title.

Will this code open the phone app with the title number?

- (IBAction)callContact:(id)sender 
{
    [[UIApplication sharedApplication] openURL: 
        [NSURL URLWithString:telfButton.titleLabel.text]];
}

It is giving me an error.

user1330343
  • 21
  • 2
  • 7

2 Answers2

0

Depends what the URL is. If its just 3033749943 it won't work. But tel://3033749943 will work just fine.

Allison
  • 2,213
  • 4
  • 32
  • 56
0

As stated in the other answer you have to use "tel://" to launch the phone app and dial the number. However, you can use NSString's stringWithFormat to add the number in the buttons title after "tel://".

- (IBAction)callContact:(id)sender 
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",telfButton.titleLabel.text]];
}
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281