Vibrate using UIFeedbackGenerator or AudioServicesPlaySystemSound

799 views Asked by At

When I want an iPhone to vibrate, how can I determine whether to use UIFeedbackGenerator or AudioServicesPlaySystemSound?

The new haptic engine is only available on iOS10 and on the iPhone 7 models, so how would we write code that uses this new engine when supported, but falls back to using the not as cool AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) when not?

Apple says to not worry about it, and that UIFeedbackGenerator simply won't do anything if not supported, but I don't see how this help me if I still want it to vibrate since its methods do not have any kind of success callback.

Note that calling these methods does not play haptics directly. Instead, it informs the system of the event. The system then determines whether to play the haptics based on the device, the application’s state, the amount of battery power remaining, and other factors.

For example, haptic feedback is currently played only:

  • On a device with a supported Taptic Engine (iPhone 7 and iPhone 7 Plus).

  • When the app is running in the foreground.

  • When the System Haptics setting is enabled.

As a general rule, trust the system to determine whether it should play feedback. Don't check the device type or app state to conditionally trigger feedback. After you’ve decided how you want to use feedback, always trigger it when the appropriate events occur. The system ignores any requests that it cannot fulfill.

0

There are 0 answers