iOS 10 iPhone 6S Play Haptic feedback or vibrate using taptic engine

前端 未结 2 699
旧巷少年郎
旧巷少年郎 2020-12-28 23:37

Iphone6s has taptic engine or not, can I use a public API called UIFeedbackGenerator to access it?

2条回答
  •  情歌与酒
    2020-12-29 00:30

    Haptic feedback engine have been introduced in iPhone7/7+ and you can use it via UIFeedbackGenerator, here's an example:

    let generator = UIImpactFeedbackGenerator(style: .heavy)
    generator.prepare()
    
    generator.impactOccurred()
    

    As for iPhone 6S/6S I've found kind of fallback, please try it and describe the experience if you do have the device:

    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)
    

    I've tried to summarize everything I found with regards to the Haptic feedback here: http://www.mikitamanko.com/blog/2017/01/29/haptic-feedback-with-uifeedbackgenerator/

提交回复
热议问题