[英]openURL for some phone numbers is failing
I'm trying to make a call programmatically to a number which has double extension. 我正在尝试以编程方式拨打具有双分机号码的电话。
When I try to run this, 当我尝试运行此程序时
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:2133776478,213#,213#"]]]
I get "No" as the response. 我得到“否”作为答复。 But when I type this number on WhatsApp, I'm allowed to make a call with this number.
但是,当我在WhatsApp上键入此号码时,可以使用该号码拨打电话。
Is there a better to achieve this? 有没有更好的办法实现这一目标? Am I missing something here?
我在这里想念什么吗?
According to the documentation , 根据文档 ,
To prevent users from maliciously redirecting phone calls or changing the behavior of a phone or account, the Phone app supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone app does not attempt to dial the corresponding phone number.
I would try using the escaped version of the telephone number first (using NSString:stringByAddingPercentEncodingWithAllowedCharacters:
), and if that fails, I would try removing the ,
and #
characters. 我会尝试先用电话号码的转义版本(使用
NSString:stringByAddingPercentEncodingWithAllowedCharacters:
如果失败,我会尝试删除,
和#
字符。
A tel: URL with a single # works, but the presence of two # characters is an invalid URL as far as NSURL
is concerned because it looks like the URL contains two anchor segments. 电话:带有单个#的URL可以使用,但是就
NSURL
而言,两个#字符的存在是无效的URL,因为看起来URL包含两个锚定段。 This results in a nil
NSURL. 结果是
nil
NSURL。
If you percent-encode your string then the # characters simply become part of the URL string and it all works: 如果您对字符串进行百分比编码,则#字符将简单地成为URL字符串的一部分,并且全部起作用:
NSString *baseString = @"tel:2133776478,213#,213#";
NSString *encodedString = [baseString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if (encodedString != nil) {
NSURL *url = [NSURL URLWithString:encodedString];
if (url != nil) {
[[UIApplication sharedApplication] openURL:url];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.