我制作了一个按钮,并将该按钮链接到以下 openPhone 方法。但它没有用。错误消息显示“线程 1:程序接收信号:“SIGABRT”。”。
我是否应该做其他我不知道的事情来让它发挥作用?谢谢
-(IBAction)openPhone{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886227637978"]];
}
我制作了一个按钮,并将该按钮链接到以下 openPhone 方法。但它没有用。错误消息显示“线程 1:程序接收信号:“SIGABRT”。”。
我是否应该做其他我不知道的事情来让它发挥作用?谢谢
-(IBAction)openPhone{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886227637978"]];
}
试试这个:- self.phone 是包含电话号码的 NSString。
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]];
-(IBAction)openPhone:(id)sender{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886227637978"]];
}
您可能还需要删除 tel:// 中的 +。我还没有测试过这些。电话号码看起来也有点长。也许这只是一个国家的事情。
还要确保它已在您的 IB 中连接并在您的 .h 中指定