6

I've already test how to make a vibration like this: How to make iPhone vibrate using Swift?

But I search how to make a very short vibration (0,5 seconds for example) in one time.

Can anyone help me? Thank you :)

Ahmed Heasat
  • 256
  • 1
  • 6
  • 22

4 Answers4

7

AFAIK you can't change the vibration duration of the "vibrate" system sound.

For shorter vibrations you could try to use taptic feedback, e.g.

let tapticFeedback = UINotificationFeedbackGenerator()
tapticFeedback.notificationOccurred(.success)
Gereon
  • 17,258
  • 4
  • 42
  • 73
4

If you have the right kind of iPhone and you're willing to confine yourself to iOS 13 and later, you can use Core Haptics to create any kind of vibration you like.

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

Pretty easy actually. First you import AVfoundation

import AVFoundation

Then create a UIDevice extension with a static function inside and call AudioServicesPlaySystemSound

extension UIDevice {
    static func vibrate() {
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
    }
}

Then use anywhere in your app like so

UIDevice.vibrate()
Timchang Wuyep
  • 629
  • 7
  • 10
0

You can try to customise your vibration by:

import AudioToolbox.AudioServices