diff --git a/android/build.gradle b/android/build.gradle index 06c8bd1..aab4a31 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -28,6 +28,11 @@ if (isNewArchitectureEnabled()) { } android { + def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION + if (agpVersion.tokenize('.')[0].toInteger() >= 7) { + namespace = "com.reactnativecommunity.geolocation" + } + compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') defaultConfig { diff --git a/android/src/main/java/com/reactnativecommunity/geolocation/AndroidLocationManager.java b/android/src/main/java/com/reactnativecommunity/geolocation/AndroidLocationManager.java index f5f901d..55d2619 100644 --- a/android/src/main/java/com/reactnativecommunity/geolocation/AndroidLocationManager.java +++ b/android/src/main/java/com/reactnativecommunity/geolocation/AndroidLocationManager.java @@ -45,10 +45,12 @@ public void onStatusChanged(String provider, int status, Bundle extras) { } @Override - public void onProviderEnabled(String provider) { } + public void onProviderEnabled(String provider) { + } @Override - public void onProviderDisabled(String provider) { } + public void onProviderDisabled(String provider) { + } }; protected AndroidLocationManager(ReactApplicationContext reactContext) { @@ -134,7 +136,8 @@ private String getValidProvider(LocationManager locationManager, boolean highAcc // If it's an enabled provider, but we don't have permissions, ignore it int finePermission = ContextCompat.checkSelfPermission(mReactContext, android.Manifest.permission.ACCESS_FINE_LOCATION); int coarsePermission = ContextCompat.checkSelfPermission(mReactContext, android.Manifest.permission.ACCESS_COARSE_LOCATION); - if (provider.equals(LocationManager.GPS_PROVIDER) && (finePermission != PackageManager.PERMISSION_GRANTED && coarsePermission != PackageManager.PERMISSION_GRANTED)) { + if ((provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) || + (provider.equals(LocationManager.NETWORK_PROVIDER) && coarsePermission != PackageManager.PERMISSION_GRANTED)) { return null; } return provider; @@ -178,13 +181,16 @@ public void onLocationChanged(Location location) { } @Override - public void onStatusChanged(String provider, int status, Bundle extras) {} + public void onStatusChanged(String provider, int status, Bundle extras) { + } @Override - public void onProviderEnabled(String provider) {} + public void onProviderEnabled(String provider) { + } @Override - public void onProviderDisabled(String provider) {} + public void onProviderDisabled(String provider) { + } }; private boolean mTriggered; @@ -209,11 +215,12 @@ public void invoke(Location location) { private static final int TWO_MINUTES = 1000 * 60 * 2; - /** Determines whether one Location reading is better than the current Location fix + /** + * Determines whether one Location reading is better than the current Location fix * taken from Android Examples https://developer.android.com/guide/topics/location/strategies.html * - * @param location The new Location that you want to evaluate - * @param currentBestLocation The current Location fix, to which you want to compare the new one + * @param location The new Location that you want to evaluate + * @param currentBestLocation The current Location fix, to which you want to compare the new one */ private boolean isBetterLocation(Location location, Location currentBestLocation) { if (currentBestLocation == null) { @@ -258,7 +265,9 @@ private boolean isBetterLocation(Location location, Location currentBestLocation return false; } - /** Checks whether two providers are the same */ + /** + * Checks whether two providers are the same + */ private boolean isSameProvider(String provider1, String provider2) { if (provider1 == null) { return provider2 == null; diff --git a/ios/RNCGeolocation.mm b/ios/RNCGeolocation.mm index 8a598f0..d7faad7 100644 --- a/ios/RNCGeolocation.mm +++ b/ios/RNCGeolocation.mm @@ -190,7 +190,9 @@ - (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccur if (@available(iOS 14.0, *)) { if ( +#if ! TARGET_OS_VISION _lastUpdatedAuthorizationStatus == kCLAuthorizationStatusAuthorizedAlways || +#endif _lastUpdatedAuthorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse ) { [self startMonitoring]; @@ -202,16 +204,24 @@ - (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccur - (void)startMonitoring { - _usingSignificantChanges - ? [_locationManager startMonitoringSignificantLocationChanges] - : [_locationManager startUpdatingLocation]; +#if !TARGET_OS_VISION + _usingSignificantChanges + ? [_locationManager startMonitoringSignificantLocationChanges] + : [_locationManager startUpdatingLocation]; +#else + [_locationManager startUpdatingLocation]; +#endif } - (void)stopMonitoring { - _usingSignificantChanges - ? [_locationManager stopMonitoringSignificantLocationChanges] - : [_locationManager stopUpdatingLocation]; +#if !TARGET_OS_VISION + _usingSignificantChanges + ? [_locationManager stopMonitoringSignificantLocationChanges] + : [_locationManager stopUpdatingLocation]; +#else + [_locationManager stopUpdatingLocation]; +#endif } #pragma mark - Timeout handler @@ -273,8 +283,10 @@ - (void)timeout:(NSTimer *)timer // Request location access permission if (wantsAlways) { +#if !TARGET_OS_VISION [_locationManager requestAlwaysAuthorization]; [self enableBackgroundLocationUpdates]; +#endif } else if (wantsWhenInUse) { [_locationManager requestWhenInUseAuthorization]; } @@ -282,6 +294,7 @@ - (void)timeout:(NSTimer *)timer - (void)enableBackgroundLocationUpdates { +#if !TARGET_OS_VISION // iOS 9+ requires explicitly enabling background updates NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"]; if (backgroundModes && [backgroundModes containsObject:@"location"]) { @@ -289,6 +302,7 @@ - (void)enableBackgroundLocationUpdates [_locationManager setAllowsBackgroundLocationUpdates:YES]; } } +#endif } @@ -445,7 +459,9 @@ - (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager } if ( +#if !TARGET_OS_VISION currentStatus == kCLAuthorizationStatusAuthorizedAlways || +#endif currentStatus == kCLAuthorizationStatusAuthorizedWhenInUse ) { if (_queuedAuthorizationCallbacks != nil && _queuedAuthorizationCallbacks.count > 0){ diff --git a/react-native-geolocation.podspec b/react-native-geolocation.podspec index c1ea11c..df45e6d 100644 --- a/react-native-geolocation.podspec +++ b/react-native-geolocation.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.authors = package['author'] s.homepage = package['homepage'] - s.platform = :ios, "9.0" + s.platforms = { :ios => '9.0', :visionos => '1.0' } s.source = { :git => "https://github.com/react-native-community/react-native-geolocation.git", :tag => "v#{s.version}" } s.source_files = "ios/**/*.{h,m,mm}"