Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISelectionFeedbackGenerator() not working on iPhone 7

I would like to use some haptic in my app. I am using the UISelectionFeedbackGenerator but it will not work. I am testing on real iPhone 7 with iOS 10. These two lines should do the magic – but nothing happens:

let generator = UISelectionFeedbackGenerator()
generator.selectionChanged()
like image 724
Kevin Lieser Avatar asked Dec 12 '16 09:12

Kevin Lieser


2 Answers

It seems as if AVFoundation (or probably just AVCaptureSession) is somehow messing with the haptic feedback! Without AVFoundation, my haptic feedback works. As soon as I put it in there, it stops working.

like image 138
ullstrm Avatar answered Nov 11 '22 20:11

ullstrm


Here are some alternatives that work on older devices:

import AudioToolbox

AudioServicesPlaySystemSound(1519) // Actuate `Peek` feedback (weak boom)
AudioServicesPlaySystemSound(1520) // Actuate `Pop` feedback (strong boom)
AudioServicesPlaySystemSound(1521) // Actuate `Nope` feedback (series of three weak booms)
like image 5
Michael Avatar answered Nov 11 '22 22:11

Michael