简体   繁体   中英

Tel URI containing * and # is not working on iOS 15 and onwards

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM