Last active
January 2, 2019 18:43
-
-
Save saoudrizwan/f8939257ea4078965dfc5b0eb34a09c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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