AccessibilityNotification.Announcement
Category: Structure
Platforms: iOS 17.0+, iPadOS 17.0+, Mac Catalyst 17.0+, macOS 14.0+, tvOS 17.0+, visionOS 1.0+, watchOS 10.0+
Overview
A notification that an app posts when it needs to convey an announcement to an assistive app.
Declaration
struct Announcement
Details
Topics
- Creating an announcement notification
- init(String)
- init(NSAttributedString)
- init(AttributedString)
See Also
- Notifications
- struct LayoutChanged
- struct ScreenChanged
-
struct PageScrolled
-
Accessibility
- AccessibilityNotification
- AccessibilityNotification.Announcement
Accessibility Notification .Announcement
Overview
Include an announcement value, such as String or AttributedString , for an assistive app to announce.
Optionally, you can apply accessibility speech attributes to the announcement. For example, you can set a priority to specify the announcement’s importance relative to other announcements that are in the queue for an assistive app to speak. Announcement priorities give you more control over which announcements people need to hear, and which ones are acceptable to ignore or interrupt.
You specify an announcement priority using the accessibilitySpeechAnnouncementPriority property. The following code shows an example of how to post an announcement notification with a high priority, which interrupts other speech and isn’t interruptible after it starts:
import SwiftUI
var body: some View {
Button(action: {
// Load the camera.
openCamera()
// Post an announcement to indicate the camera is done loading.
var highPriorityAnnouncement = AttributedString("Camera active")
highPriorityAnnouncement.accessibilitySpeechAnnouncementPriority = .high
AccessibilityNotification.Announcement(highPriorityAnnouncement).post()
}) {
Image("Camera")
}
Topics (Grouped)
Creating an announcement notification
- initString) — (; Creates an announcement notification with a string.
- initNSAttributedString) — (; Creates an announcement notification with an attributed string value.
- initAttributedString) — (; Creates an announcement notification with an attributed string object.
Notifications
- LayoutChanged — struct; A notification that an app posts when the layout of a screen changes.
- ScreenChanged — struct; A notification that an app posts when a new view appears that occupies a major portion of the screen.
- PageScrolled — struct; A notification that an app posts when a scroll action completes.
Code Examples
struct Announcement
import SwiftUI
var body: some View {
Button(action: {
// Load the camera.
openCamera()
// Post an announcement to indicate the camera is done loading.
var highPriorityAnnouncement = AttributedString("Camera active")
highPriorityAnnouncement.accessibilitySpeechAnnouncementPriority = .high
AccessibilityNotification.Announcement(highPriorityAnnouncement).post()
}) {
Image("Camera")
}
}
Source: https://developer.apple.com/documentation/accessibility/accessibilitynotification/announcement