React-native: [iOS] Vibration.vibrate not working at all

Created on 12 Feb 2019  路  11Comments  路  Source: facebook/react-native

馃悰 Bug Report

Using Vibration.vibrate produces the following results:

TypeError: undefined is not an object (evaluating 'RCTVibration.vibrate')
in MyComponent (at ComponentWrapper.js:27)
in WrappedComponent (at renderApplication.js:32)
in RCTView (at View.js: 43)
in RCTView (at VIew.js: 43)
in AppContainer (at renderApplication.js: 31)

Screenshot

To Reproduce

Simply add Vibration.vibrate() at convenient location then test on iOS on RN 0.56.0

Expected Behavior

The device should vibrate

Code Example

Snack

Environment

React Native Environment Info:

  • System:

    • OS: macOS 10.14.3

    • CPU: x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz

    • Memory: 11.24 GB / 24.00 GB

    • Shell: 5.3 - /bin/zsh

  • Binaries:

    • Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node

    • Yarn: 1.12.3 - /usr/local/bin/yarn

    • npm: 6.4.1 - ~/.nvm/versions/node/v10.14.1/bin/npm

    • Watchman: 4.9.0 - /usr/local/bin/watchman

  • SDKs:

    • iOS SDK:

    • Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1

    • Android SDK:

    • Build Tools: 27.0.3, 28.0.3

    • API Levels: 27, 28

  • IDEs:

    • Android Studio: 3.3 AI-182.5107.16.33.5264788

    • Xcode: 10.1/10B61 - /usr/bin/xcodebuild

  • npmPackages:

    • react: 16.6.3 => 16.6.3

    • react-native: 0.56.0 => 0.56.0

  • npmGlobalPackages:

    • react-native-create-library: 3.1.2

Vibration Author Feedback Repro iOS

Most helpful comment

This is still not working on iOS, though no exception is thrown for me. Vibration.vibrate() yields no feedback whatsoever.

All 11 comments

It looks like you are using an older version of React Native. Please update to the latest release, v0.58 and verify if the issue still exists.

The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

You're missing a required parameter, the vibration pattern. See http://facebook.github.io/react-native/docs/vibration#vibrate

Vibration.vibrate(pattern: number, Array<number>, repeat: boolean)

You're missing a required parameter, the vibration pattern. See http://facebook.github.io/react-native/docs/vibration#vibrate

Vibration.vibrate(pattern: number, Array<number>, repeat: boolean)

Using
const DURATION = 1000
Vibration.vibrate(DURATION)

or
const PATTERN = [1000,2000,3000]
Vibration.vibrate(PATTERN)

Produces the same result: undefined is not an object (evaluating 'RCTVibration.vibrate')

I believe this is just an old version problem, since Vibration.vibrate() works without any parameter just fine on RN 0.58 on both iOS and Android. Just reporting the issue for documentation purposes.

According to https://github.com/facebook/react-native/blob/master/Libraries/Vibration/Vibration.js#L72, vibrate() should throw an error. It doesn't look like the code has changed recently.

If it works fine in 0.58 and it's only an issue in 0.56, then that's alright as we're only tracking issues that affect the latest release.

If it's more of a docs concern, and something needs to be documented differently for 0.56, you can open an issue in the docs repo at https://github.com/facebook/react-native-website

@hramos the code has a 400 duration by default, which is mentioned on the docs, but also is mentioned as a required parameter (which it really doesn't)
Vibration.vibrate(400) and Vibration.vibrate() have the same result on the device.

Can confirm, doesn't work on most recent react-native also. Same error.

using RN 0.60 I do not get an error thrown but the Vibration does not occur at all on IOS. Android works fine on Single Values, but on Pattern it does not change, it seems only the highest value is taken in the Array.

This is still not working on iOS, though no exception is thrown for me. Vibration.vibrate() yields no feedback whatsoever.

Interesting. Reopening as I just sent a PR to update the docs to match the implementation on iOS.

I just tested this on RNTester, by navigating to the Vibration example. It works just fine on iOS. In fact, all variants of Vibration.vibrate(), including those with patterns and repetition, vibrated as expected (even on iOS, where the docs claim it'd only vibrate once). I don't see any errors on Metro or on the Xcode console.

These are the steps I followed, in a fresh checkout of the RN repo:

npm install
npm start
cd RNTester
pod install
open RNTesterPods.xcworkspace

Then I selected RNTester as the target, and my own iOS physical device, an iPhone 11 Pro Max. Build and Run, then type "Vibration" into the search field in RNTester. Then tap each of the vibrate() examples. Each time, the device vibrated.

I'll leave this open for a bit in case someone can provide a repro. But for now, I consider this to not be an issue on master.

It's been three weeks since we asked for additional information from the author of this issue. As it happens, we don't have enough information to take action. We are going to close this issue, but please do not hesitate to open a new issue if you are still encountering this problem.

Was this page helpful?
0 / 5 - 0 ratings