IOS app vibration/haptic feedback?

Is there anyway to get an IOS app in xojo to access the vibration motor?

This is not built in to Xojo, but perhaps it is available in one of the open-source iOS frameworks such as iOSKit or AppleLib.

It’s not available in iOSKit but it shouldn’t be that difficult to implement in declares. Let me know if you have questions, there are good examples in the Apple docs on what you need to do.

Declares should be simple (I’m not a declare nor a “Xojo for iOS” guy)… but Haptic feedback is part of UIKit so all the parts should be accessible

https://www.appcoda.com/haptic-feedback/

I use the code, below, to vibrate the device in some situations as an additional cue for the user:

Public Sub Vibrate()
  Const kSystemSoundID_Vibrate = 4095
  Declare Sub AudioServicesPlaySystemSound Lib "AudioToolbox.framework" (snd As Integer)
  AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
End Sub

[quote=405937:@Jason Tait]I use the code, below, to vibrate the device in some situations as an additional cue for the user:

Public Sub Vibrate() Const kSystemSoundID_Vibrate = 4095 Declare Sub AudioServicesPlaySystemSound Lib "AudioToolbox.framework" (snd As Integer) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) End Sub [/quote]

This is an excellent solution for most basic needs. Vibration as cue is a welcome addition in a lot of cases and a necessity when accessibility is important (as it always should), since custom controls may not trigger it automatically.

If Jason Tait’s Code doesn’t work for me, @Jason King how would I implement IOSkit and make a declare to access haptic feedback?

This worked great in my quick test. I’ve added it to the iOS Declare page.

got “The page cannot be found”

Same here 404 Error

@Jonathon Ar You’ll need to implement the declares here: https://developer.apple.com/documentation/uikit/uifeedbackgenerator?language=objc

[quote=405937:@Jason Tait]I use the code, below, to vibrate the device in some situations as an additional cue for the user:

Public Sub Vibrate() Const kSystemSoundID_Vibrate = 4095 Declare Sub AudioServicesPlaySystemSound Lib "AudioToolbox.framework" (snd As Integer) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) End Sub [/quote]
This one has been in iOSKit a while :wink: I just didn’t think thats what was desired.

Sorry Jason I wasn’t trying to take credit for your code :). I don’t have this in my copy of iOSKit but I do remember adapting some code for playing system sounds that I found and then finding and adding the constant for vibrate in Apple’s docs.

Sorry about the 404 – forgot to hit publish. Page is available now.

http://developer.xojo.com/declare-ios

I also need haptic feedback so I added it to iOSKit and created a pull request:
https://github.com/kingj5/iOSKit/pull/16

The pull request has been merged. Thanks @Jeremie Leroy !

@Paul Lefebvre @Jason Tait What iPhones are supported for this? I have seen that only iPhone 7 and up support this is that true?

Yes iPhone 7 and up.
That’s why I wasn’t able to really test my addition to iOSKit on my iPhone SE.

More info: https://medium.com/nerdmade/ios-haptic-feedback-for-iphone-7-and-6s-1bc6e7f1c285

[quote=406179:@Jeremie Leroy]Yes iPhone 7 and up.
That’s why I wasn’t able to really test my addition to iOSKit on my iPhone SE.

More info: https://medium.com/nerdmade/ios-haptic-feedback-for-iphone-7-and-6s-1bc6e7f1c285[/quote]
Actually, the article says iPhone 6s and up. You confused me for a sec… I’m typing on a 6s and I know it has support :slight_smile:

Well the article says that iPhone 7 is supported through an API (the one I added to iOSKit). iPhone 6s support isn’t exposed and uses undocumented function parameters.