Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active July 17, 2018 18:44
Show Gist options
  • Select an option

  • Save saoudrizwan/92605cc1807b78e308fa2e7e00ac9f96 to your computer and use it in GitHub Desktop.

Select an option

Save saoudrizwan/92605cc1807b78e308fa2e7e00ac9f96 to your computer and use it in GitHub Desktop.
Haptic feedback UINotificationFeedbackGenerator example for iOS 10
import UIKit
let notificationFeedbackGenerator = UINotificationFeedbackGenerator()
// We can inform the feedback generator that it will likely receive events soon,
// which basically 'wakes up' the device's taptic engine for a few seconds,
// preparing it for use without any latency. You can call this function as many
// times as you want. Good times to call this are when a gesture begins and right
// after a haptic signal is played.
notificationFeedbackGenerator.prepare()
// Play the desired haptic signals
notificationFeedbackGenerator.notificationOccurred(.success)
notificationFeedbackGenerator.notificationOccurred(.warning)
notificationFeedbackGenerator.notificationOccurred(.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment