我正在构建一个应用程序,让您可以拨打荷兰的不同服务中心.问题是它们中的一些具有不同的商业格式(如0800-xxxx),并且设备无法拨打电话.代码如下所示:
if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
[[UIApplication sharedApplication] openURL:phoneURL];
}
Run Code Online (Sandbox Code Playgroud)
您知道如何格式化号码或拨打电话,无论格式如何?
编辑:这是phoneNumber的创建方式:
NSString *phoneNumberString = phoneNumber; // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", phoneNumberString];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
Run Code Online (Sandbox Code Playgroud)
And*_*scu 27
我使用了这段代码并且它有效:
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *phoneURLString = [NSString stringWithFormat:@"telprompt:%@", escapedPhoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
[[UIApplication sharedApplication] openURL:phoneURL];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5190 次 |
| 最近记录: |