Skip to content

UINotificationFeedbackGenerator ​

UINotificationFeedbackGenerator represents a notification-type haptic feedback generator: the vibration for when something succeeded, needs attention, or failed. The three outcomes have different vibration patterns.

Inheritance: EventTarget → NSObject → UIFeedbackGenerator → UINotificationFeedbackGenerator

In the simulator, or when the user has turned off haptic feedback, calls do not throw but there is no vibration; see When there is no vibration.

Constructor ​

It cannot be created with new; use UINotificationFeedbackGenerator.feedbackGeneratorForView(). Using new throws TypeError, and the error message names the static method to use.

Static methods ​

UINotificationFeedbackGenerator.feedbackGeneratorForView()

Creates a generator bound to a view.

Instance methods ​

Also inherits prepare() from UIFeedbackGenerator.

MethodDescription
notificationOccurred()Vibrates with the pattern for one of success, warning, and error

Examples ​

js
const page = new UIViewController();
const alarm = UINotificationFeedbackGenerator.feedbackGeneratorForView(page.view);
alarm.notificationOccurred('error');

Effect: The phone vibrates with the pattern the system defines for "error", which differs from the pattern for "success". The feel of the vibration is not verified in the simulator.

Corresponding iOS API ​

ObjCJS
[UINotificationFeedbackGenerator feedbackGeneratorForView:view]UINotificationFeedbackGenerator.feedbackGeneratorForView(view)
[generator notificationOccurred:UINotificationFeedbackTypeSuccess]generator.notificationOccurred('success')

See also ​