Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play tick sound of UIPickerView on iOS 10?

The title has it... There is a new sound on iOS 10 that UIPickerView plays each time the selected item is changed. Is there a way to play that sound? Ideally with AudioServicesPlaySystemSound(_) if there is system sound for it or in any other way if there is not any.

like image 245
Rasto Avatar asked Oct 24 '25 13:10

Rasto


1 Answers

I have the same problem and I finally found a solution

AudioServicesPlaySystemSoundWithCompletion(1157, nil);

AudioServicesPlaySystemSound will be deprecated in a future release. Use AudioServicesPlaySystemSoundWithCompletion instead.

If you want to mimic the sound and vibration of UIPickerView, you should also add the following code.

if (@available(iOS 10.0, *)) {
    UIImpactFeedbackGenerator *impactFeedBack = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
    [impactFeedBack prepare];
    [impactFeedBack impactOccurred];
}
like image 177
Shaun Avatar answered Oct 26 '25 04:10

Shaun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!