Skip to content

Commit 5a5f200

Browse files
authored
feat: add visionos support (#327)
1 parent f123ae2 commit 5a5f200

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

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)