user4806509
user4806509

Reputation: 3011

How to add VoiceOver accessibility to an App's Icon Badge Number?

Question:

How do I add a custom VoiceOver accessibility Label or Hint to an App Icon Badge Number?

enter image description here           enter image description here           enter image description here


For example, when the iOS Setting Accessibility > VoiceOver is turned On, VoiceOver reads aloud items touched on screen. For the App Store and Mail icons, the following is read out aloud:

App Store icon, VoiceOver says: "App Store. 2 updates available. Double tap to open."

Mail icon, VoiceOver says: "Mail. 1 unread message. Double tap to open."

But, for the project I am working on, the VoiceOver read out is generic and not entirely helpful:

My App icon, VoiceOver says: "My App. 123 new items. Double tap to open."

The phrase "... new items" is too vague, not accurate, and I'm certain there must be a way to change this with a custom string to make it read better through setting an accessibilityLabel, accessibilityHint or something similar.

But how exactly in Swift code?

Many thanks.


Additional observation:

Using the Simulator Accessibility Inspector, it appears the VoiceOver values come from Label - "My App" and Value - "123 new items". So updated in the code I have tried setting the accessibilityValue to something custom - "123 custom description.". But still no luck, VoiceOver continues to read "My App. 123 new items. Double tap to open."

Why isn't VoiceOver reading the custom badge value as expected?

enter image description here


Code:

The below method adds a red circle App Icon Badge Number to My App's icon:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let badgeCount: Int = 123
        let application = UIApplication.sharedApplication()
        if #available(iOS 8.0, *) { 
            //// iOS 8, iOS 9, iOS 10
            application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Badge], categories: nil))
        } else {
            //// iOS 7
        }
        application.applicationIconBadgeNumber = badgeCount
        application.accessibilityValue = "123 custom description."
    }
}

Upvotes: 15

Views: 2439

Answers (1)

BHendricks
BHendricks

Reputation: 4493

It appears this is an "Apple-only" feature as of now... source

Digging through API documentation, there doesn't seem to be any identifier that can set this for you, and I therefore think it's not publicly supported yet. It's likely been reported already, but reporting this as a request to Apple can never hurt.

Sorry this is probably not the answer you were hoping for! :/

Upvotes: 5

Related Questions