Skip to content

Commit 99f5636

Browse files
Merge branch 'master' of github.com:michalchudziak/react-native-geolocation
2 parents 39fb46d + f388394 commit 99f5636

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ if (isNewArchitectureEnabled()) {
2828
}
2929

3030
android {
31+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
32+
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
33+
namespace = "com.reactnativecommunity.geolocation"
34+
}
35+
3136
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
3237

3338
defaultConfig {

android/src/main/java/com/reactnativecommunity/geolocation/AndroidLocationManager.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
4545
}
4646

4747
@Override
48-
public void onProviderEnabled(String provider) { }
48+
public void onProviderEnabled(String provider) {
49+
}
4950

5051
@Override
51-
public void onProviderDisabled(String provider) { }
52+
public void onProviderDisabled(String provider) {
53+
}
5254
};
5355

5456
protected AndroidLocationManager(ReactApplicationContext reactContext) {
@@ -134,7 +136,8 @@ private String getValidProvider(LocationManager locationManager, boolean highAcc
134136
// If it's an enabled provider, but we don't have permissions, ignore it
135137
int finePermission = ContextCompat.checkSelfPermission(mReactContext, android.Manifest.permission.ACCESS_FINE_LOCATION);
136138
int coarsePermission = ContextCompat.checkSelfPermission(mReactContext, android.Manifest.permission.ACCESS_COARSE_LOCATION);
137-
if (provider.equals(LocationManager.GPS_PROVIDER) && (finePermission != PackageManager.PERMISSION_GRANTED && coarsePermission != PackageManager.PERMISSION_GRANTED)) {
139+
if ((provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) ||
140+
(provider.equals(LocationManager.NETWORK_PROVIDER) && coarsePermission != PackageManager.PERMISSION_GRANTED)) {
138141
return null;
139142
}
140143
return provider;
@@ -178,13 +181,16 @@ public void onLocationChanged(Location location) {
178181
}
179182

180183
@Override
181-
public void onStatusChanged(String provider, int status, Bundle extras) {}
184+
public void onStatusChanged(String provider, int status, Bundle extras) {
185+
}
182186

183187
@Override
184-
public void onProviderEnabled(String provider) {}
188+
public void onProviderEnabled(String provider) {
189+
}
185190

186191
@Override
187-
public void onProviderDisabled(String provider) {}
192+
public void onProviderDisabled(String provider) {
193+
}
188194
};
189195
private boolean mTriggered;
190196

@@ -209,11 +215,12 @@ public void invoke(Location location) {
209215

210216
private static final int TWO_MINUTES = 1000 * 60 * 2;
211217

212-
/** Determines whether one Location reading is better than the current Location fix
218+
/**
219+
* Determines whether one Location reading is better than the current Location fix
213220
* taken from Android Examples https://developer.android.com/guide/topics/location/strategies.html
214221
*
215-
* @param location The new Location that you want to evaluate
216-
* @param currentBestLocation The current Location fix, to which you want to compare the new one
222+
* @param location The new Location that you want to evaluate
223+
* @param currentBestLocation The current Location fix, to which you want to compare the new one
217224
*/
218225
private boolean isBetterLocation(Location location, Location currentBestLocation) {
219226
if (currentBestLocation == null) {
@@ -258,7 +265,9 @@ private boolean isBetterLocation(Location location, Location currentBestLocation
258265
return false;
259266
}
260267

261-
/** Checks whether two providers are the same */
268+
/**
269+
* Checks whether two providers are the same
270+
*/
262271
private boolean isSameProvider(String provider1, String provider2) {
263272
if (provider1 == null) {
264273
return provider2 == null;

ios/RNCGeolocation.mm

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ - (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccur
190190

191191
if (@available(iOS 14.0, *)) {
192192
if (
193+
#if ! TARGET_OS_VISION
193194
_lastUpdatedAuthorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
195+
#endif
194196
_lastUpdatedAuthorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse
195197
) {
196198
[self startMonitoring];
@@ -202,16 +204,24 @@ - (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccur
202204

203205
- (void)startMonitoring
204206
{
205-
_usingSignificantChanges
206-
? [_locationManager startMonitoringSignificantLocationChanges]
207-
: [_locationManager startUpdatingLocation];
207+
#if !TARGET_OS_VISION
208+
_usingSignificantChanges
209+
? [_locationManager startMonitoringSignificantLocationChanges]
210+
: [_locationManager startUpdatingLocation];
211+
#else
212+
[_locationManager startUpdatingLocation];
213+
#endif
208214
}
209215

210216
- (void)stopMonitoring
211217
{
212-
_usingSignificantChanges
213-
? [_locationManager stopMonitoringSignificantLocationChanges]
214-
: [_locationManager stopUpdatingLocation];
218+
#if !TARGET_OS_VISION
219+
_usingSignificantChanges
220+
? [_locationManager stopMonitoringSignificantLocationChanges]
221+
: [_locationManager stopUpdatingLocation];
222+
#else
223+
[_locationManager stopUpdatingLocation];
224+
#endif
215225
}
216226

217227
#pragma mark - Timeout handler
@@ -273,22 +283,26 @@ - (void)timeout:(NSTimer *)timer
273283

274284
// Request location access permission
275285
if (wantsAlways) {
286+
#if !TARGET_OS_VISION
276287
[_locationManager requestAlwaysAuthorization];
277288
[self enableBackgroundLocationUpdates];
289+
#endif
278290
} else if (wantsWhenInUse) {
279291
[_locationManager requestWhenInUseAuthorization];
280292
}
281293
}
282294

283295
- (void)enableBackgroundLocationUpdates
284296
{
297+
#if !TARGET_OS_VISION
285298
// iOS 9+ requires explicitly enabling background updates
286299
NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
287300
if (backgroundModes && [backgroundModes containsObject:@"location"]) {
288301
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
289302
[_locationManager setAllowsBackgroundLocationUpdates:YES];
290303
}
291304
}
305+
#endif
292306
}
293307

294308

@@ -445,7 +459,9 @@ - (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager
445459
}
446460

447461
if (
462+
#if !TARGET_OS_VISION
448463
currentStatus == kCLAuthorizationStatusAuthorizedAlways ||
464+
#endif
449465
currentStatus == kCLAuthorizationStatusAuthorizedWhenInUse
450466
) {
451467
if (_queuedAuthorizationCallbacks != nil && _queuedAuthorizationCallbacks.count > 0){

react-native-geolocation.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
1010

1111
s.authors = package['author']
1212
s.homepage = package['homepage']
13-
s.platform = :ios, "9.0"
13+
s.platforms = { :ios => '9.0', :visionos => '1.0' }
1414

1515
s.source = { :git => "https://github.com/react-native-community/react-native-geolocation.git", :tag => "v#{s.version}" }
1616
s.source_files = "ios/**/*.{h,m,mm}"

0 commit comments

Comments
 (0)