Is there some kind of UIAccessibility Alert Tone?
Asked Answered
D

3

8

Is there any way to get iOS to play the tone that UIActionSheet plays when presented? It’s a sudden beep followed by the word "Alert".

I've searched the documentation and haven't been able to find anything that looks appropriate.

Diathermic answered 3/2, 2014 at 21:56 Comment(1)
My only idea is: figure out the audio framework UIAccessibility uses, swizzle the method used to play sounds and breakpoint it so you can get a stack trace, and cross your fingers that it's not a private API.Wileywilfong
R
2

Not all behaviors of system controls can be reimplemented exactly using the UIAccessibility protocol. There is no public API to issue an accessibility hint tone like that. What you can do, however, is describe the control and transition in such a way that VoiceOver and other assistive clients know to alert the user.

Depending on how your app is implemented, you might need to notify UIAccessibility that screen content has changed using UIAccessibilityPostNotification(), which accepts two parameters: the notification type and object. For a screen change notification, the object represents the next element that should receive focus. VoiceOver will process this notification, issue a tone, and move the cursor to the specified element.

In general, you shouldn't be trying to "get UIAccessibility to" do anything at all. The protocol lets you describe the content and state of your app. It's up to each assistive client to translate these descriptions into an alternative interface as it sees fit. VoiceOver is not the only accessibility feature that relies on UIAccessibility! If you ape its behavior in your app, you could confuse VoiceOver users and alienate users of other assistive features such as Switch Control.

Edit: Another answer suggests playing the sound yourself. Once again, I'd strongly recommend against introducing your own sounds for scenarios already covered by VoiceOver. System sound icons convey more than just the context. They also assure users that a particular control is standard and predictable, implementing all expected behaviors. For quick example, does your custom sheet support the two-finger scrub gesture (accessibility escape)? The system sheet does and people will expect it if they hear the sheet sound.

Roca answered 6/2, 2014 at 20:5 Comment(0)
H
0

There are many ways to play audio with help of System Sound Services, AVAudioPlayer, Audio Queue Services, and OpenAL. Without outside support libraries, the two easiest ways by far are System Sound Services and AVAudioPlayer.

when will you have click button you can play, play at delay time, duration play etc., here the example for AVAudioPlayer

   NSError *error;
   AVAudioPlayer *alertSound = [[AVAudioPlayer alloc]
        initWithContentsOfURL:musicURL error:&error];
    [alertSound prepareToPlay];
    [alertSound play];

Edited:

- (BOOL)playAtTime:(NSTimeInterval)time

The number of seconds to delay playback, relative to the audio output device’s current time.

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html#//apple_ref/occ/instm/AVAudioPlayer/playAtTime:

Henghold answered 11/2, 2014 at 9:28 Comment(0)
C
0

I'm fairly sure that the sounds that you are taking about comes from the "screen change" notification. It is an accessibility notification that is (from the documentation)

posted by an application when a new view appears that comprises a major portion of the screen.

When you post if within your application then you can pass either a string that will be read or the element that focus should move to. In the case of the alert view, focus moves to the alert view so I would assume that UIKit posts the alert view as the second argument.

To do this for your own view, you would do something like this:

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
                                yourNewViewThatShouldGetFocus);
Cosmopolitan answered 11/2, 2014 at 9:37 Comment(2)
That's actually a different sound.Diathermic
what about UIAccessibilityLayoutChangedNotification ("layout" instead of "screen")?Anthrax

© 2022 - 2024 — McMap. All rights reserved.