'Phone numbers are read with special characters in swift IOS when voice over is on

I have these dynamic accessibility text coming down from server and it could be as below.

Dial: 1-800-425-9456 Dial: 425-295-2958

On the client I am setting this to button controls accessibility Text. However, when voice over reads phone number with country code, it is reading the last hypen for 1-800-425-9456 (1 800 425 hypen 9456)

When it reads phone number without country code like 425-295-2958 , it just reads as 425 295 2958.

I want to make sure when a string containing phone number is read, the special characters like (),- etc within the phone numbers are not read. IOS contacts app does not read special characters except the + that prefixes country code some times.

The code I have is

button.accessibiityLabel = serverString

Any pointers on what more to do to avoid reading special characters within the phone number.



Solution 1:[1]

In general you shouldn't try to force a screen reader to announce things a certain way. I was able to replicate your problem in iOS Voiceover. I hadn't noticed it before. The last hyphen is indeed spoken in the first example, although Voiceover says "minus" instead of "hyphen" for me. The second example doesn't announce the hyphen. I added a '+' in front of the country code but that still causes the last hyphen to be announced.

The user has some control over this. They can go into Settings > Accessibility > Voiceover > Verbosity > Numbers and change the pronunciation from "Words" to "Numbers". That causes all the digits and all the punctuation to be read, which is the opposite of what you want. All the hyphens are announced.

enter image description here

Alternatively, if you can post-process the phone number and remove all the punctuation and change them to blanks, then you can set the accessibility label to "1 800 425 9456" but still display "1-800-425-9456".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 slugolicious