25

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.

user185813
  • 481
  • 1
  • 5
  • 16
  • 1
    "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. – Dimitris Sep 08 '16 at 09:04

4 Answers4

50

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!

Valentin Shergin
  • 7,166
  • 2
  • 50
  • 53
  • 3
    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 – Henry Ngan Apr 22 '16 at 16:52
  • 1
    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. – Valentin Shergin Apr 22 '16 at 17:34
  • 1
    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. – Henry Ngan Apr 22 '16 at 17:36
  • 1
    My app (which is using this way to actuate taptic feedback) successfully passed App Review process. Yay! (Thank you, Apple!) – Valentin Shergin Jun 13 '16 at 20:33
  • This is amazing. I'd be interested to know how you figured these existed though. – Kane Cheshire Aug 10 '16 at 10:42
  • 2
    Those calls do not work on iOS 10 Beta 6 for me anymore. – Legoless Aug 19 '16 at 09:15
  • 2
    Works on iOS 10.0.2 (: – Aviel Gross Sep 28 '16 at 09:58
  • @AvielGross That's awesome! Thank you for confirming. – Valentin Shergin Sep 28 '16 at 10:05
  • From AudioServices.h: "This function will be deprecated in a future release. Use AudioServicesPlaySystemSoundWithCompletion instead." – Linasses Oct 08 '16 at 12:04
  • @ValentinShergin do you have the 'magic' constants for UIImpactFeedbackGenerator? – DVassilev Feb 10 '17 at 13:54
  • These don't work on 10.2 and above from what I can see on my end – Shai Mishali Jun 19 '17 at 16:39
  • In case there's anyone else out there still targeting iOS 9 in 2021… Word from Apple (on an [Apple Developer Forums post](https://developer.apple.com/forums/thread/45628) 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." – George WS Jun 27 '21 at 07:12
18

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.

Legoless
  • 10,942
  • 7
  • 48
  • 68
  • 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? – Bri Bri Oct 19 '15 at 16:48
  • Thanks for the comment. I do believe that would be a hardware limitation. Otherwise, I do not have an idea how to do this. – Legoless Oct 19 '15 at 18:10
  • @kelin The link works, but it should be https, even though the browser should do a redirect. Can you try again? – Legoless Dec 26 '16 at 11:37
10

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.

Tuslareb
  • 1,200
  • 14
  • 21
  • Interesting. I wonder what kind of limitation there is that excludes the 6S(+) from using these APIs. – Andy Ibanez Sep 18 '16 at 18:15
  • I don't know. Maybe it's the different kind of (physical) taptic engine, maybe it will be fixed in a future iOS update. – Tuslareb Sep 18 '16 at 18:55
  • 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*. – mxcl Dec 04 '16 at 17:26
2

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

Woodstock
  • 22,184
  • 15
  • 80
  • 118