Skip to content

Commit

Permalink
feat: add visionos support (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Aug 31, 2024
1 parent f123ae2 commit 5a5f200
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions ios/RNCGeolocation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -273,22 +283,26 @@ - (void)timeout:(NSTimer *)timer

// Request location access permission
if (wantsAlways) {
#if !TARGET_OS_VISION
[_locationManager requestAlwaysAuthorization];
[self enableBackgroundLocationUpdates];
#endif
} else if (wantsWhenInUse) {
[_locationManager requestWhenInUseAuthorization];
}
}

- (void)enableBackgroundLocationUpdates
{
#if !TARGET_OS_VISION
// iOS 9+ requires explicitly enabling background updates
NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
if (backgroundModes && [backgroundModes containsObject:@"location"]) {
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
[_locationManager setAllowsBackgroundLocationUpdates:YES];
}
}
#endif
}


Expand Down Expand Up @@ -445,7 +459,9 @@ - (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager
}

if (
#if !TARGET_OS_VISION
currentStatus == kCLAuthorizationStatusAuthorizedAlways ||
#endif
currentStatus == kCLAuthorizationStatusAuthorizedWhenInUse
) {
if (_queuedAuthorizationCallbacks != nil && _queuedAuthorizationCallbacks.count > 0){
Expand Down
2 changes: 1 addition & 1 deletion react-native-geolocation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 5a5f200

Please sign in to comment.