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.
| Method | Description |
|---|---|
notificationOccurred() | Vibrates with the pattern for one of success, warning, and error |
Examples
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
| ObjC | JS |
|---|---|
[UINotificationFeedbackGenerator feedbackGeneratorForView:view] | UINotificationFeedbackGenerator.feedbackGeneratorForView(view) |
[generator notificationOccurred:UINotificationFeedbackTypeSuccess] | generator.notificationOccurred('success') |
See also
- Making the phone vibrate
UIFeedbackGenerator: the base class