Taptic in iOS 9

10,282

Solution 1

Yay, I had reverse engineered internal UIKit stuff and I found another (much simpler) way to actuate feedback via TapticEngine! We can just use AudioToolbox framework and several magic constants.

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)

Hope this helps!

Solution 2

There is currently no public available API in iOS 9 and iOS 9.1.

Disclaimer: There is a way to interact with Taptic Engine directly, but there is a private method. You should not use it in App Store applications.

However, if you are more into experimenting, then you can find that there is a new private class available in iOS 9: _UITapticEngine. You can find it's header here. To get to it, there is a new property on UIDevice class, called _tapticEngine. See the full header for UIDevice here. You can go ahead and import those headers, or just use NSSelectorFromString function and performSelector: method to get to the taptic engine:

id tapticEngine = [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"_tapticEngine") withObject:nil];
[tapticEngine performSelector:NSSelectorFromString(@"actuateFeedback:") withObject:@(1001)]; // Peek
[tapticEngine performSelector:NSSelectorFromString(@"endUsingFeedback:") withObject:@(1002)]; // Pop

This will activate the taptic engine for specific gesture, although both Peek and Pop feel similar to me. If you specify any other constant, it will default to a vibration.

I have put together a quick test repo together on GitHub, that includes a Swift-compatible API to use the taptic engine:

UIDevice.currentDevice().tapticEngine().actuateFeedback(UITapticEngineFeedbackPeek)

Use at your own risk!

I've also written a bit longer blog post, explaining this.

Solution 3

In iOS 10 there's a new API called UIFeedbackGenerator. See this post for more details. It only works on the iPhone 7 for now.

Solution 4

There doesn't seem to be a published API for iOS 9 currently.

On OSX you need to use NSHapticFeedbackManager:

NSHapticFeedbackManager Class Reference

and here is the API for WatchOS2:

WKInterfaceDevice Class Reference

By simply searching here you can see what I'm saying:

Haptic search (iOS pre-release) - shows nothing

Haptic search (OSX pre-release) - shows NSHapticFeedbackManager

Share:
10,282

Related videos on Youtube

user185813
Author by

user185813

Updated on July 13, 2022

Comments

  • user185813
    user185813 almost 2 years

    Can you use the taptic engine in iOS 9 with iPhone 6s? WatchOS2 and OS X have the ability to use the haptic engine, so I assumed it would be in iOS 9 too, but I coudn't find any APIs for it.

    • Dimitris
      Dimitris almost 8 years
      "Taptic Engine API" was mentioned on the 07 Sept 16 Apple Keynote, so, no it's not on iOS9 but it seems to be coming soon.
  • rmaddy
    rmaddy almost 9 years
    The question is about iOS 9. You've posted links for OS X and WatchOS.
  • Bri Bri
    Bri Bri over 8 years
    Thanks for figuring out how to do this, and making a great blog post about it. I tried using this in a little app experiment of mine but found that when using the actuateFeedback method there was a limit to the rate of peak or pop feedback I could trigger, something like 5 or 6 per second. Do you know if there's any way to trigger these at a faster rate?
  • Legoless
    Legoless over 8 years
    Thanks for the comment. I do believe that would be a hardware limitation. Otherwise, I do not have an idea how to do this.
  • Henry Ngan
    Henry Ngan about 8 years
    Wow this is amazing!! However does this count as a private API? They did include AudioServicesPlaySystemSound in the API reference but they didn't state what the numbers mean :O
  • Valentin Shergin
    Valentin Shergin about 8 years
    This is philosophical question. In terms of App Store review process, any non-public API considers as private, but technically speaking almost any API usage can be obfuscated/hidden from Review Team. I think main issue here is appropriate or inappropriate usage of any particular API.
  • Henry Ngan
    Henry Ngan about 8 years
    thanks for your reply. I'm trying to incorporate this into my WWDC scholarship app and I don't wanna get rejected because of this. I just submitted the question to Apple and I'll update this if they have any comment on this.
  • Valentin Shergin
    Valentin Shergin about 8 years
    My app (which is using this way to actuate taptic feedback) successfully passed App Review process. Yay! (Thank you, Apple!)
  • Kane Cheshire
    Kane Cheshire almost 8 years
    This is amazing. I'd be interested to know how you figured these existed though.
  • Legoless
    Legoless almost 8 years
    Those calls do not work on iOS 10 Beta 6 for me anymore.
  • Andy Ibanez
    Andy Ibanez almost 8 years
    Interesting. I wonder what kind of limitation there is that excludes the 6S(+) from using these APIs.
  • Tuslareb
    Tuslareb almost 8 years
    I don't know. Maybe it's the different kind of (physical) taptic engine, maybe it will be fixed in a future iOS update.
  • Aviel Gross
    Aviel Gross almost 8 years
    Works on iOS 10.0.2 (:
  • Valentin Shergin
    Valentin Shergin almost 8 years
    @AvielGross That's awesome! Thank you for confirming.
  • Linasses
    Linasses over 7 years
    From AudioServices.h: "This function will be deprecated in a future release. Use AudioServicesPlaySystemSoundWithCompletion instead."
  • mxcl
    mxcl over 7 years
    Don't provide links, the average link half-life on the Internet is THREE HOURS. StackOverflow is hopefully forever, but only if its content is here.
  • Legoless
    Legoless over 7 years
    @kelin The link works, but it should be https, even though the browser should do a redirect. Can you try again?
  • DVassilev
    DVassilev over 7 years
    @ValentinShergin do you have the 'magic' constants for UIImpactFeedbackGenerator?
  • Shai Mishali
    Shai Mishali about 7 years
    These don't work on 10.2 and above from what I can see on my end
  • George WS
    George WS about 3 years
    In case there's anyone else out there still targeting iOS 9 in 2021… 🙃 Word from Apple (on an Apple Developer Forums post that I think may be from @HenryNgan above) is: "It would not be appropriate to use undocumented arbitrary values in APIs, so I would recommend you not do that in your submission."