iOS Haptic feedback API, like shown on stage.

Today, during iPhone 7 event, Instagram shown their app on stage, and it has featured Haptic feedback functionality(80:45), even though it is not available for other developers and is frowned upon by Apple review if you use undocumented ways to enable haptic feedback . My questions is, when will other developers get access to Haptic feedback API?

Accepted Reply

There is new public API coming in iOS 10 that will allow you to provide haptic feedback. In the GM version of Xcode 8 you can look at UIFeedbackGenerator, and its UIImpactFeedbackGenerator, UISelectionFeedbackGenerator, and UINotificationFeedbackGenerator.

Replies

There is new public API coming in iOS 10 that will allow you to provide haptic feedback. In the GM version of Xcode 8 you can look at UIFeedbackGenerator, and its UIImpactFeedbackGenerator, UISelectionFeedbackGenerator, and UINotificationFeedbackGenerator.

Is it only available on iPhone 7 and 7 Plus?

I tried all 3 feedback types in the new API on my iPhone 6S and none worked, but I may have been doing something wrong. The 6S clearly has some sort of haptic capability, but maybe this is still unavailable to developers.

How is the prepare method expected to be used? For example I have implemented a force touch gesture and want to give feedback when the user presses hard enough to initiate it. Would it make sense to call prepare whenever the user touches the display and then invoke the feedback only if enough force is detected? Or should you only call it when you know that feedback is very likely to be required rather than just a possibility? I don't want to slow down the UI every time the user touches the screen on the off-chance that they will perform the gesture.

"prepare" is a matter of power usage vs latency. It takes longer to play a haptic if the taptic engine isn't prepared, but takes more power to keep the engine running.


In your case, preparing the taptic engine on touch down is likely reasonable.


And yes, the new APIs are only available on iPhone 7 and iPhone 7 Plus, previous iterations of iPhone don't support the patterns or usage that the new API allows for.

Many thanks for that. I'll call prepare on touch down then. Do you know how long the engine stays running for? If it is longer than a few seconds then I will rewrite my code. There doesn't seem to be any way to tell the taptic engine to "stand down" when the user stops touching, so it looks like I should create the feedback object on the touch start, and delete it on the touch ending (assuming that will stop the engine).


At the moment I am creating it once for the view and re-using it, but it sounds more power efficient to create it on each touch. Do you know if this is how the API is intended to be used when calling prepare is only occasionally followed by a request to give haptic feedback (such as for a touch resulting in a peek/pop)?


I was hoping that some sort of limited API would be available for use on the 6S. My gesture uses a couple of touch levels, so I was hoping to provide the same haptic feedback that the OS uses for peek and then pop. Is there an API that allows 3rd party apps to do this on the 6S?


Thanks again.

When you ask to prepare, we keep the engine warm for a short time, under the expectation that a request will come in "soon". So latency vs power is really all a matter of if you can predict when a haptic will play. If you feel that you will "often" play a haptic after touch down, then prewarming is good for latency and won't cost much in power. Conversely if you "rarely" play a haptic after touch down, your paying a lot of cost for latency. I don't know the actual tradeoff point between "often" and "rarely", but you might try seeing how it feels without the prepare call and if you think it still feels good, then don't bother with it.


Preperation of the playback engine is independent of the feedback generators you create – so your first instinct of creating and reusing is correct.


For Peek & Pop like feedback, you can use the UIPreviewInteraction class, which will allow you to put your own visuals on top of the standard feedback progression that you get from the Peek & Pop feature.

That’s very useful thanks. I can’t afford a new iPhone 7 so I will err on the side of caution and not call prepare on touch down, because most touches will not result in feedback. If there is a slight delay then I will live with it, but I don’t want to keep the haptic engine in a constant state of readiness every time the user touches the screen if it dramatically affects power usage.


I already use UIPreviewInteraction for standard peek/pop, but my gesture is very different. My app involves maps and if you force touch on the map then it zooms out. Press harder and it zooms out further. The user can then move their finger to the area they wish to pan to, then let go and it zooms back into that new area. If they move near the edge of the screen then it pans in that direction whilst zoomed out.


At the moment I only allow two discrete zoom levels (continuous zooming didn't feel right), so I was hoping to emulate the same haptic feedback as used for peek/pop (which also has two force levels).

Yes. It's 7/7+ exclusive.