$ npm install react-native-compass-heading --save
$ react-native link react-native-compass-heading
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-compass-headingand addRNCompassHeading.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNCompassHeading.ato your project'sBuild Phases➜Link Binary With Libraries - Run your project (
Cmd+R)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNCompassHeadingPackage;to the imports at the top of the file - Add
new RNCompassHeadingPackage()to the list returned by thegetPackages()method
- Append the following lines to
android/settings.gradle:include ':react-native-compass-heading' project(':react-native-compass-heading').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-compass-heading/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle:compile project(':react-native-compass-heading')
- In Visual Studio add the
RNCompassHeading.slninnode_modules/react-native-compass-heading/windows/RNCompassHeading.slnfolder to their solution, reference from their app. - Open up your
MainPage.csapp
- Add
using Compass.Heading.RNCompassHeading;to the usings at the top of the file - Add
new RNCompassHeadingPackage()to theList<IReactPackage>returned by thePackagesmethod
import RNCompassHeading from 'react-native-compass-heading';
//Example code
getHeadingCompass = async () => {
await RNCompassHeading.initSensor(); //init the Device Sensor, it's async Method
let degree = await RNCompassHeading.getHeading(); //get the Degree, it's async and get resolved with a int (degree), it is executed only one time
//do something with the degree value
}