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

前端 未结 2 694
旧巷少年郎
旧巷少年郎 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/

    0 讨论(0)
  • 2020-12-29 00:32

    iPhone 7 has a more precise, more flexible Taptic Engine than iPhone 6s — you can use the UIFeedbackGenerator class cluster to get at the richer vocabulary of haptic feedback signals that iPhone 7 supports, but these APIs have no effect on iPhone 6s (or other devices).

    iPhone 6s still has a Taptic Engine, but it's not as capable as the newer one — it supports only the haptic signals associated with 3D Touch features. However, it is possible to use those in your app:

    • to build a standard Peek/Pop UI (haptics included) into your app, use standard views that already do it (like table and collection views), set peek/pop segues in your storyboard, and/or adopt the UIViewControllerPreviewing and UIViewControllerPreviewingDelegate protocols in your view controller. You can do this in iOS 9.

    • to provide peek/pop gesture support — including the accompanying haptic feedback — without a UI, or with your own custom UI, use the UIPreviewInteraction class and its delegate protocol. This part requires iOS 10.

    For more info about peek/pop, 3D Touch, and haptics in general, see the WWDC16 session "A Peek at 3D Touch" and Apple's guide to Adopting 3D Touch on iPhone.

    0 讨论(0)
提交回复
热议问题