iOS Question Vibrate Phone (Short Vibrate)

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to make the phone vibrate when a button is pressed.

I have found that I can use code like:

B4X:
Dim vib As Phone
    vib.Vibrate

However, when I use this code it seems that it vibrates the phone for approx 1 second.

Is there a way in making it vibrate the phone for 100-200ms (like a short keypress vibrate) rather than a long vibration like it's doing now ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.
B4X:
Private FeedbackGenerator As NativeObject 'globals
2. Initialize:
B4X:
FeedbackGenerator.Initialize("UIImpactFeedbackGenerator")
If FeedbackGenerator.IsInitialized Then
   FeedbackGenerator = FeedbackGenerator.RunMethod("alloc", Null).RunMethod("initWithStyle:", Array(0)) 'light
End If
3. Vibrate:
B4X:
If FeedbackGenerator.IsInitialized Then
           FeedbackGenerator.RunMethod("impactOccurred", Null)
       End If
 
Upvote 0
Top