4

I'm trying to provide custom text for voiceover user instead of reading the body text.

E.g., the current body text is say "Apple stock $203.03 ↑" it reads as "Apple stock two hundred three dollars and three cents up arrow" but I wanted to read as "Apple stock two hundred three dollars and three cents in green"

The following code did not work:

let content = UNMutableNotificationContent()
content.body = "Apple stock $203.03 ↑"
content.accessibilityLabel = "Apple stock two hundred three dollars and three cents in green"
content.accessibilityHint = "I am an Hint"

Even the hint is not spoken.

Let me know if it is possible to achieve this?

Is there anyway to achieve this in default notification ( Notification Content Extension works only after user expand the notification)

XLE_22
  • 5,124
  • 3
  • 21
  • 72
palaniraja
  • 10,432
  • 5
  • 43
  • 76
  • Have you found out any solution that could remove my bug report about your question since I wrote my answer, please? – XLE_22 Dec 08 '21 at 13:54
  • 1
    @XLE_22 No. Created Radar/Feedback ticket no update. And followed up with Accessibility evangelist, they said it is in their system/backlog, that is all :-( – palaniraja Dec 08 '21 at 21:48

2 Answers2

2

Let me know if it is possible to achieve this?

Actually, you can't.
I wrote a Developer Technical Support Incident (no 731462771) whose Apple's answer definitely admits that it's a bug they can't provide a workaround.

I submitted a bug report entitled VoiceOver: can't change change accessibilityLabel for UNMutableNotificationContent with the reference FB7640821 in order to fix this problem as soon as possible (the next iOS version ? ).

Now, you know why you can't provide custom accessibility text for iOS local notification content... until it's fixed by Apple itself.

XLE_22
  • 5,124
  • 3
  • 21
  • 72
1

Base on this answer here:

Try to set the accessibilityValue like:

content.accessibilityValue = "Apple stock two hundred three dollars and three cents in green"

If it does not work, try setting the accessibilityLabel to the value you want and subclassing the UNMutableNotificationContent to override the accessibilityValue property.

class CustomUNMutableNotificationContent: UNMutableNotificationContent {
    override public var accessibilityValue: String? {
        get { return self.accessibilityLabel }
        set { super.accessibilityValue = newValue }
    }
}
André
  • 356
  • 1
  • 6
  • I just saw the code you printed, in the subclass when overriding the `accessibilityValue` you're returning the `accessibilityValue` again. Can you replace it with `accessibilityLabel` and see if it works? – André Jul 30 '19 at 03:29
  • Ok... instead, if you override the `accessibilityValue` and returns the text "Apple stock two hundred three dollars and three cents in green" instead of the `accessibilityLabel`, does it says it correctly? – André Jul 30 '19 at 18:57