Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vibration.cancel() doesn't work on iOS #63

Closed
miri-red opened this issue Nov 8, 2021 · 4 comments
Closed

Vibration.cancel() doesn't work on iOS #63

miri-red opened this issue Nov 8, 2021 · 4 comments

Comments

@miri-red
Copy link

miri-red commented Nov 8, 2021

I have vibration turned on with a pattern but in some cases I want the vibration to stop earlier, so I use Vibration.cancel().
On android it works great but on iOS it seems to continue to vibrate until the pattern is done.

@benjamindean
Copy link
Owner

If I remember correctly, there is no method to stop the pattern on iOS. I'll check once again.

@baobao2304
Copy link

hi benjamindean what do you think about AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate) ?

@benjamindean
Copy link
Owner

@baobao2304 That might work, but not for the pattern unfortunately.

@baobao2304
Copy link

@benjamindean I think this is not bad , you can try that , its worked with me .

bool isCheckStop = false;
int counter = 0;
Timer? timer;

void startVibrationIOS(){
timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (counter < 20) {

  if(isCheckStop) {
    isCheckStop = false;
    counter = 0 ;
    timer.cancel();
  }
  else{
    if(counter % 2 == 0) {
      Vibration.vibrate(duration: 500);
    }
    else {
      Vibration.vibrate(duration: 1000);
    }
  }
} else{

  timer.cancel();
  counter = 0 ;

}
});
}

void stopVibrationIOS(){
    isCheckStop = true;
}

void startVibrate(){
    if(Platform.isAndroid){
        Vibration.vibrate(
        pattern: List.generate(20, (index) => index % 2 == 0 ? 500 : 1000));
    }else{
        startVibrationIOS();
    }
}

void stopVibrate() {
    if(Platform.isAndroid){
        Vibration.cancel();
    }else{
        stopVibrationIOS();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants