Search code examples
swiftxcodevibrationhaptic-feedback

How to recreate Haptic Feedback Vibration when you long press on app icon


How can I recreate the exact vibration that happens when you hold down on an app icon like this in swift?enter image description here

The same vibration can be felt when you swipe on a message on Facebook messenger to reply to it.


Solution

  • You can use a UIFeedbackGenerator for this, for example:

    UINotificationFeedbackGenerator().notificationOccurred(.success)

    or

    UISelectionFeedbackGenerator().selectionChanged()