Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active January 2, 2019 18:43
Show Gist options
  • Select an option

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

Select an option

Save saoudrizwan/f8939257ea4078965dfc5b0eb34a09c7 to your computer and use it in GitHub Desktop.
// Initialize in viewDidLoad
let mediumImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
// Prepare in viewDidAppear
mediumImpactFeedbackGenerator.prepare()
// Play haptic signal
if let feedbackSupportLevel = UIDevice.current.value(forKey: "_feedbackSupportLevel") as? Int {
switch feedbackSupportLevel {
case 2:
// 2nd Generation Taptic Engine w/ Haptic Feedback (iPhone 7/7+)
mediumImpactFeedbackGenerator.impactOccurred()
case 1:
// 1st Generation Taptic Engine (iPhone 6S/6S+)
let peek = SystemSoundID(1519)
AudioServicesPlaySystemSound(peek)
case 0:
// No Taptic Engine
break
default: break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment