palaniraja
palaniraja

Reputation: 10492

How do I provide custom accessibility text for ios local notification content - UNNotificationContent

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)

Upvotes: 4

Views: 956

Answers (2)

XLE_22
XLE_22

Reputation: 5671

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. 😉

Upvotes: 2

André
André

Reputation: 326

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 }
    }
}

Upvotes: 1

Related Questions