Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taptic in iOS 9

Tags:

ios

ios9

iphone

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.

like image 302
user185813 Avatar asked Sep 11 '15 15:09

user185813


3 Answers

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!

like image 134
Valentin Shergin Avatar answered Nov 16 '22 03:11

Valentin Shergin


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.

like image 21
Legoless Avatar answered Nov 16 '22 02:11

Legoless


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.

like image 27
Tuslareb Avatar answered Nov 16 '22 03:11

Tuslareb