包含 *和#的TEL URI不在iOS 15上工作

发布于 2025-01-24 05:43:04 字数 542 浏览 3 评论 0 原文

包含 *和#的TEL URIS不在iOS 15及以后。当我尝试执行以下语句时,

[UIApplication.sharedApplication openURL:[NSURL URLWithString:@"tel://*21*12345#"] options:@{} completionHandler:nil];

它没有在设备上显示任何内容。

NSString *numberToDial = @"*21*12345#";
NSString *encodedNumberToDial = [numberToDial stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", encodedNumberToDial]];

我也尝试对其进行编码,但它不起作用。

Tel URIs containing * and # are not working on iOS 15 and onwards. When I try to execute the following statement

[UIApplication.sharedApplication openURL:[NSURL URLWithString:@"tel://*21*12345#"] options:@{} completionHandler:nil];

It didn't show anything on the device.

NSString *numberToDial = @"*21*12345#";
NSString *encodedNumberToDial = [numberToDial stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", encodedNumberToDial]];

I also try to encode it but it didn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2025-01-31 05:43:04

根据文档:

为了防止用户恶意重定向电话或更改电话或帐户的行为,电话应用程序在TEL方案中最多但并非全部都支持。具体来说,如果URL包含 *或#字符,则电话应用程序不会尝试拨打相应的电话号码。如果您的应用程序从用户或未知来源接收URL字符串,则还应确保正确逃脱了任何可能不合适的特殊字符。对于本机应用程序,请使用StringByAddingPercentEscapesSudingEncusinging:NSString的方法逃脱字符,它返回了原始字符串的正确逃脱版本。

看来这是API的限制,并且由于安全性而设计。

According to the docs: https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

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. If your app receives URL strings from the user or an unknown source, you should also make sure that any special characters that might not be appropriate in a URL are escaped properly. For native apps, use the stringByAddingPercentEscapesUsingEncoding: method of NSString to escape characters, which returns a properly escaped version of your original string.

It appears that this is a limitation of the API and by design because of security.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文