benjamindean / flutter_vibration

Handle vibration on iOS and Android in Flutter apps
217 stars 67 forks source link

iOS errors - vibrate with custom duration and vibration cancel not working #90

Open jan-koz opened 10 months ago

jan-koz commented 10 months ago

Calling Vibration.vibrate() with custom duration has no impact on iOS, vibration length is 500 ms. It's possible to vibrate with pattern to achieve custom duration. Also as in title canceling vibration on iOS is not working. Checked on iPhone 13, iOS 16.1.1

Filiponesco commented 9 months ago

Yes, it's true.

  1. Vibration.vibrate() with custom duration has no impact on iOS: Call AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) when not specified pattern argument: `

        guard let pattern = myArgs["pattern"] as? [Int] else {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
            result(true)
            return
        }
        if pattern.count == 0 {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
            result(true)
            return
        }

    `

  2. Canceling vibration on iOS is not working: There is no implementation: case "cancel": result(nil)

shubhamsinghmutualmobile commented 3 months ago

Yes, it's true.

  1. Vibration.vibrate() with custom duration has no impact on iOS: Call AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) when not specified pattern argument: `
        guard let pattern = myArgs["pattern"] as? [Int] else {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
            result(true)
            return
        }
        if pattern.count == 0 {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
            result(true)
            return
        }

`

  1. Canceling vibration on iOS is not working: There is no implementation: case "cancel": result(nil)

This should be mentioned in the documentation to allow end users to utilise this library to its max potential 🌟 Until I discovered this issue, I legit believed there's something wrong with my iPhone 11 😆

Pasting a quick working sample for future readers. Use this code on iOS to control vibration intensity to your liking:

Future<void> vibrate() async {
final canVibrate = await Vibration.hasVibrator() ?? false;
    if (canVibrate) {
        await Vibration.vibrate(pattern: [16], intensities: [200]);
    }
}

Here, pattern can be considered as duration, and intensities define how strong should the vibration(s) be.