make phone vibrate on UIButton click

670 Views Asked by At

I was trying to implement vibration functionality on the click of UIButton with following line of code:

import AudioToolbox

AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

But nothing happens. if someone has an experience regarding this, please check the issue.

1

There are 1 best solutions below

0
rodfleischer On

You're probably better off using haptic feedback if the device supports it (eg iPhone).

let feedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
feedbackGenerator.impactOccurred()