Haptic Feedback in iOS 10+

I recently revisited an old iOS app and wanted to add some haptic feedback to certain actions. Apple has introduced 3 different types of vibrations from their documentation:

UIImpactFeedbackGenerator. Use impact feedback generators to indicate that an impact has occurred. For example, you might trigger impact feedback when a user interface object collides with something or snaps into place.

UISelectionFeedbackGenerator. Use selection feedback generators to indicate a change in selection.

UINotificationFeedbackGenerator. Use notification feedback generators to indicate successes, failures, and warnings.

However, all the example code I found online were in Swift. My old app is written in Objective C, so I figured out how to call each of these haptic types in Objective C.

The iOS simulator does not currently provide a way to test these vibrations, so you’ll need to use your iPhone to feel your changes.

Leave a Reply

Your email address will not be published. Required fields are marked *