3

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.

Rasto
  • 17,204
  • 47
  • 154
  • 245

2 Answers2

7

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];
}
ink
  • 519
  • 6
  • 19
0

You can use system click sounds or save them and use from local resources

//  NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/wheels_of_time.caf"]; // Too loud
//  NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/nano/TimerWheelHoursDetent_Haptic.caf"]; // Hours tick
SystemSoundID soundID;
NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/nano/TimerWheelMinutesDetent_Haptic.caf"]; // Minutes tick
AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)fileURL, &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);
FunkyKat
  • 3,233
  • 1
  • 23
  • 20