asq-react-native-sensors v1.1.0
React Native Sensors
React Native bridge to access device sensors.
Installation
Minimum Requirements
react-native | iOS |
---|---|
0.50 | 10.3 |
NPM package
npm install asq-react-native-sensors
Getting started
Add
node-modules/asq-react-native-sensors/ios/ASQSensors.xcodeproj
to your LibrariesAdd
libASQSensors.a
under Link Binary With Libraries in Build PhasesAdd
$(SRCROOT)/../node_modules/asq-react-native-sensors/ios/ASQSensors
to your Header Search Paths in Build Settings
Usage - Gyroscope
import { Gyroscope } from "asq-react-native-sensors";
Gyroscope.isActive
Asynchroneous function to check if Gyroscope is avaliable or already active, resolves promise if Gyroscope is already active, otherwise errors if its not avaliable or is not active.
try {
await Gyroscope.isActive();
} catch (e) {
if (e.message === 'Error: NOT_ACTIVE') {
// If gyroscope is avaliable but not active subscribe
Gyroscope.setInterval(300)
Gyroscope.subscribe(callback);
} else {
// gyroscope is not avaliable, your logic here
}
}
Gyroscope.setInterval
Set interval to specify refresh rate of data flow from Gyroscope in ms
Gyroscope.setInterval(100);
Gyroscope.subscribe
Subscribe to gyroscope events, expects callback that handles gyroscope data
Gyroscope.subscribe(callback);
function callback(data) {
console.log(
`x: ${data.x}, y: ${data.y}, z: ${data.z}, timestamp: ${data.timestamp}`
);
}
Gyroscope.unsubscribe
Always unsubscribe from Gyroscope events when they are not needed i.e.
in componentWillUnmount
Gyroscope.unsubscribe();