Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make phone call by using UIApplication sharedApplication

I made a button, and link the button to the following openPhone method. But it didn't work. Error message shows "Thread 1:Program received signal: "SIGABRT".".

Should I do anything else that I do not know to let it work? Thanks

-(IBAction)openPhone{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886227637978"]];
}
like image 952
lavitanien Avatar asked May 02 '26 03:05

lavitanien


1 Answers

try this:- self.phone is NSString that contain phone number.

    NSString *telephoneString=[self.phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSMutableString *str1=[[NSMutableString alloc] initWithString:telephoneString];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"(" withString:@""]];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@")" withString:@""]];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"-" withString:@""]];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@" " withString:@""]];
    telephoneString = [@"tel://" stringByAppendingString:str1];
    [str1 release];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneString]];
like image 139
Gypsa Avatar answered May 03 '26 21:05

Gypsa