From edb4ce9ec0af7426c80e352412722e1f07dc97df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20Joachim=20R=C3=B8rvik?= Date: Fri, 8 Dec 2017 10:01:52 +0100 Subject: [PATCH 1/3] Added a podspec file and updated Readme for usage with Cocoapods --- README.md | 11 +++++++++ react-native-simple-compass.podspec | 38 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 react-native-simple-compass.podspec diff --git a/README.md b/README.md index a063e64..30fe249 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,17 @@ #### iOS +##### Using CocoaPods + +To install with CocoaPods, add the following to your Podfile: + +``` +pod 'react-native-simple-compass', :path => '../node_modules/react-native-simple-compass' +``` + +Then run pod install and rebuild your project. + +##### Manual installation 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 2. Go to `node_modules` ➜ `react-native-simple-compass` and add `RNSimpleCompass.xcodeproj` 3. In XCode, in the project navigator, select your project. Add `libRNSimpleCompass.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` diff --git a/react-native-simple-compass.podspec b/react-native-simple-compass.podspec new file mode 100644 index 0000000..8f55757 --- /dev/null +++ b/react-native-simple-compass.podspec @@ -0,0 +1,38 @@ +Pod::Spec.new do |s| + + # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.name = "react-native-simple-compass" + s.version = "1.0.0" + s.summary = "Some summary" + s.description = <<-DESC +This is a great description + DESC + + s.homepage = "https://github.com/vnil/react-native-simple-compass" + + # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.license = "MIT" + + # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.author = { "Some guy" => "some.guy@internett.com" } + + # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.platform = :ios, "9.0" + + # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.source = { :git => "https://github.com/vnil/react-native-simple-compass" } + + # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.source_files = 'ios/**/*.{h,m}' + + # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + + s.dependency "React" + +end From 1edea47d9b9b7c9874ea3813674fa1841dc4a7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20Joachim=20R=C3=B8rvik?= Date: Fri, 5 Jan 2018 12:48:38 +0100 Subject: [PATCH 2/3] Added accuracy --- .../com/reactlibrary/RNSimpleCompassModule.java | 16 +++++++++++----- index.js | 5 ++--- ios/RNSimpleCompass.m | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/reactlibrary/RNSimpleCompassModule.java b/android/src/main/java/com/reactlibrary/RNSimpleCompassModule.java index 5e27cba..507fb22 100644 --- a/android/src/main/java/com/reactlibrary/RNSimpleCompassModule.java +++ b/android/src/main/java/com/reactlibrary/RNSimpleCompassModule.java @@ -1,4 +1,3 @@ - package com.reactlibrary; import android.hardware.Sensor; @@ -14,6 +13,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.WritableMap; public class RNSimpleCompassModule extends ReactContextBaseJavaModule implements SensorEventListener { @@ -21,6 +21,7 @@ public class RNSimpleCompassModule extends ReactContextBaseJavaModule implements private static Context mApplicationContext; private int mAzimuth = 0; // degree + private int mAccuracy = 0; private int mFilter = 1; private SensorManager mSensorManager; private Sensor mSensor; @@ -62,7 +63,7 @@ public void stop() { @Override public void onSensorChanged(SensorEvent event) { - if( event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR ){ + if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { // calculate th rotation matrix SensorManager.getRotationMatrixFromVector(rMat, event.values); // get the azimuth value (orientation[0]) in degree @@ -75,15 +76,20 @@ public void onSensorChanged(SensorEvent event) { mAzimuth = newAzimuth; + WritableMap params = Arguments.createMap(); + params.putInt("degree", mAzimuth); + params.putInt("accuracy", mAccuracy); + getReactApplicationContext() .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) - .emit("HeadingUpdated", mAzimuth); + .emit("HeadingUpdated", params); } } - @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { - + if (sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { + mAccuracy = accuracy; + } } } diff --git a/index.js b/index.js index 644bc31..13140b6 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ - import { NativeModules, NativeEventEmitter } from 'react-native'; const { RNSimpleCompass } = NativeModules; @@ -12,8 +11,8 @@ RNSimpleCompass.start = (update_rate, callback) => { } const compassEventEmitter = new NativeEventEmitter(RNSimpleCompass); - listener = compassEventEmitter.addListener('HeadingUpdated', (degree) => { - callback(degree); + listener = compassEventEmitter.addListener('HeadingUpdated', (degree, accuracy) => { + callback(degree, accuracy); }); _start(update_rate === null ? 0 : update_rate); diff --git a/ios/RNSimpleCompass.m b/ios/RNSimpleCompass.m index 17c6655..13e504a 100644 --- a/ios/RNSimpleCompass.m +++ b/ios/RNSimpleCompass.m @@ -40,7 +40,7 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading if (newHeading.headingAccuracy < 0) { return; } - [self sendEventWithName:kHeadingUpdated body:@(newHeading.trueHeading)]; + [self sendEventWithName:kHeadingUpdated body:@{@"degree": @(newHeading.trueHeading), @"accuracy": @(newHeading.headingAccuracy)}]; } - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { From 1dfa34791dc53eb098500e41f1685d04813e2609 Mon Sep 17 00:00:00 2001 From: "Kim A. Martinsen" Date: Fri, 19 Jan 2018 15:03:59 +0100 Subject: [PATCH 3/3] Remove requesting location when library opens --- ios/RNSimpleCompass.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ios/RNSimpleCompass.m b/ios/RNSimpleCompass.m index 13e504a..a5e92b0 100644 --- a/ios/RNSimpleCompass.m +++ b/ios/RNSimpleCompass.m @@ -15,10 +15,6 @@ - (instancetype)init { if ([CLLocationManager headingAvailable]) { self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; - if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) { - NSLog(@"Requesting permission"); - [self.locationManager requestWhenInUseAuthorization]; - } } else { NSLog(@"Heading not available");