Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

[Bug] [iOS] Vibration.Vibrate not working in some case

Open Twelve57 opened this issue 5 years ago • 14 comments

Description

I've created and subscribed to an EventHandler to catch the beginning of an event (in my case the Audio Recorder with a Start to record method) In this method callback, I call the Vibration.Vibrate method of Essentials to vibrate the device. I've double checked the event callback method and also displayed a toast message in this method using the ACR.Userdialogs plugin and the toast is displayed as expected. But the vibration works only Android and not on my iOS devices.

EDIT: To be more precise, the vibration works outside the callback. It failed only when I try to execute the vibration inside the EventHandler callback and only for iOS. But the Toast and the other methods calls works perfectly... it's very weird.

Steps to Reproduce

  1. Create and Subscribe to an EventHandler to catch the beginning of an event
  2. In this callback/event method call the Vibration.Vibrate method of the Essentials Plugin

Expected Behavior

The vibration should works on Android AND iOS devices.

Actual Behavior

The vibration works only on Android devices.

Basic Information

  • Version with issue: 1.3.1
  • Last known good version: -
  • IDE: VS for mac
  • Platform Target Frameworks:
    • iOS: 8.0
    • Android: 9.0
  • Affected Devices: iPhone 6 with 12.4.3 iPhone 7 Plus with 13.3

Twelve57 avatar Feb 04 '20 09:02 Twelve57

Assumption here is you may need to invoke on main thread. Can you try that and see.

Also make sure that your device is set to vibrate on ring.

jamesmontemagno avatar Feb 05 '20 16:02 jamesmontemagno

Yes I already tried that. The only difference it's the call from the Event Handler callback. And yes, the devices are set to vibrate on ring.

Like I said, the vibration works for all of my pages, but not in a Event Handler method on an iOS Device... really weird :x

Twelve57 avatar Feb 05 '20 16:02 Twelve57

do you have a small sample we can test out? are you saying like in an event handler for a button click?

jamesmontemagno avatar Feb 07 '20 16:02 jamesmontemagno

@Twelve57 did you ever manage to get this working?

mattleibow avatar Nov 06 '20 01:11 mattleibow

Nope :/

Twelve57 avatar Nov 06 '20 14:11 Twelve57

Have the same issue. Any solutions?

SangI762 avatar Nov 29 '20 19:11 SangI762

do you have a small sample we can test out? are you saying like in an event handler for a button click?

jamesmontemagno avatar Dec 02 '20 23:12 jamesmontemagno

It's simple like that. iOS 14.2 iPhone 11 Pro, XCode 12.2, Xamarin.Essentials 1.5.3.2

public override void ViewDidLoad()
{
    //Works
    Vibration.Vibrate();
    MyButton.TouchUpInside += OnButtonClick;
}

public void OnButtonClick(object sender, EventArgs e)
{
    //Not working
    Vibration.Vibrate();
   
    //Other stuff
}

SangI762 avatar Dec 03 '20 06:12 SangI762

What if you call run on main thread in that OnButtonClick?

jamesmontemagno avatar Dec 03 '20 19:12 jamesmontemagno

Tried. Not working too. Also tried this one:

 SystemSound.Vibrate.PlayAlertSound();
            MainThread.BeginInvokeOnMainThread(() =>
            {
                SystemSound.Vibrate.PlayAlertSound();
            });

Not working too in event handler. But works in view did load method. So I suspect that is Xamarin.iOS bug...

SangI762 avatar Dec 03 '20 19:12 SangI762

interesting, yeah i think it isn't us at that point, very strange....

jamesmontemagno avatar Dec 04 '20 00:12 jamesmontemagno

Maybe you can use the haptic feedback for this? Maybe newer versions of iOS need new permissions or something?

mattleibow avatar Dec 04 '20 12:12 mattleibow

I tried haptic feedback too and it's not working also. My issue was that I'm using microphone at the same time. It's camera view... So it's not a bug I guess. Can't use vibration with microphone, right?

SangI762 avatar Dec 06 '20 19:12 SangI762

Any updates?

jl-mobitech avatar Mar 06 '23 07:03 jl-mobitech