ram
ram

Reputation: 1193

how to open call making /dialing numer view open when button press?

enter code here-(IBAction)Call:(id)sender{
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://18005551234"]];
/*NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel:%@",phoneNumber.text];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];*/
NSURL *url = [ [ NSURL alloc ] initWithString: @"tel:212-555-1234" ];
[[UIApplication sharedApplication] openURL:url]; 

} in above code i use various method but no one working. when i implement a break-point on function then it say this is out of scope. what is problem in this?

Upvotes: 1

Views: 547

Answers (1)

EmptyStack
EmptyStack

Reputation: 51374

You should remove the hypens "-", and also the brackets "(", ")" from the phone number. No special characters should be there except numbers.

NSCharacterSet *specialCharSet = [NSCharacterSet characterSetWithCharactersInString:@" )(-,"];
NSArray *components = [phoneNumber.text componentsSeparatedByCharactersInSet:specialCharSet];
NSString *phoneStr = [components componentsJoinedByString:@""];
phoneStr = [NSString stringWithFormat:@"tel:%@", phoneStr];
NSURL *url = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:url]; 

Upvotes: 2

Related Questions