Skip to content

Commit

Permalink
apple: enable corelocation location driver (#17595)
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven authored Feb 19, 2025
1 parent d818cb8 commit 8bf7e76
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 7 deletions.
2 changes: 0 additions & 2 deletions griffin/griffin.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,6 @@ LOCATION
============================================================ */
#if defined(ANDROID)
#include "../location/drivers/android.c"
#elif defined(HAVE_CORELOCATION)
#include "../location/drivers/corelocation.m"
#endif

/*============================================================
Expand Down
4 changes: 4 additions & 0 deletions griffin/griffin_objc.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
#include "../audio/drivers/coreaudio3.m"
#endif

#ifdef HAVE_CORELOCATION
#include "../location/drivers/corelocation.m"
#endif

#if defined(HAVE_DISCORD)
#include "../deps/discord-rpc/src/discord_register_osx.m"
#endif
Expand Down
31 changes: 27 additions & 4 deletions location/drivers/corelocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ - (instancetype)init {
}

- (void)requestAuthorization {
if (_locationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined) {
CLAuthorizationStatus status;
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *))
status = [_locationManager authorizationStatus];
else
status = [CLLocationManager authorizationStatus];

if (status == kCLAuthorizationStatusNotDetermined)
[_locationManager requestWhenInUseAuthorization];
}
else
[self locationManager:_locationManager didChangeAuthorizationStatus:status];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
Expand All @@ -64,8 +71,18 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
self.authorized = (status == kCLAuthorizationStatusAuthorizedWhenInUse ||
status == kCLAuthorizationStatusAuthorizedAlways);
#if TARGET_OS_OSX
if (@available(macOS 10.12, *))
self.authorized = (status == kCLAuthorizationStatusAuthorizedAlways);
#elif TARGET_OS_IPHONE
if (@available(iOS 8.0, tvOS 9.0, *))
self.authorized = (status == kCLAuthorizationStatusAuthorizedWhenInUse ||
status == kCLAuthorizationStatusAuthorizedAlways);
#endif
#if !TARGET_OS_TV
if (self.authorized)
[_locationManager startUpdatingLocation];
#endif
}

@end
Expand Down Expand Up @@ -118,8 +135,14 @@ static bool corelocation_get_position(void *data, double *lat, double *lon,
if (!corelocation || !corelocation->manager.authorized)
return false;

#if TARGET_OS_TV
CLLocation *location = [corelocation->manager.locationManager location];
*lat = location.coordinate.latitude;
*lon = location.coordinate.longitude;
#else
*lat = corelocation->manager.latitude;
*lon = corelocation->manager.longitude;
#endif
*horiz_accuracy = 0.0; // CoreLocation doesn't provide this directly
*vert_accuracy = 0.0; // CoreLocation doesn't provide this directly
return true;
Expand Down
1 change: 1 addition & 0 deletions pkg/apple/BaseConfig.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OTHER_CFLAGS = $(inherited) -DHAVE_CLOUDSYNC
OTHER_CFLAGS = $(inherited) -DHAVE_COCOA_METAL
OTHER_CFLAGS = $(inherited) -DHAVE_CONFIGFILE
OTHER_CFLAGS = $(inherited) -DHAVE_COREAUDIO
OTHER_CFLAGS = $(inherited) -DHAVE_CORELOCATION
OTHER_CFLAGS = $(inherited) -DHAVE_DR_FLAC
OTHER_CFLAGS = $(inherited) -DHAVE_DR_MP3
OTHER_CFLAGS = $(inherited) -DHAVE_DSP_FILTER
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/OSX/Info_Metal.plist
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2024 RetroArch. All rights reserved.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Some cores can use location.</string>
<key>NSMainNibFile</key>
<string>MainMenu_Metal</string>
<key>NSMicrophoneUsageDescription</key>
Expand Down
8 changes: 8 additions & 0 deletions pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
072976DD296284F600D6E00C /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 072976DC296284F600D6E00C /* OpenGL.framework */; };
0746953A2997393000CCB7BD /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 074695362995C03900CCB7BD /* GameController.framework */; };
075650252C488918004C5E7E /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 075650242C488918004C5E7E /* CloudKit.framework */; };
076512622D64E99200E1F6BE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076512612D64E99200E1F6BE /* CoreLocation.framework */; };
076512632D64E99A00E1F6BE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076512612D64E99200E1F6BE /* CoreLocation.framework */; };
076512642D64E9A000E1F6BE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076512612D64E99200E1F6BE /* CoreLocation.framework */; };
076E640C2BF30A7A00681536 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0795A8C6299A095300D5035D /* CoreHaptics.framework */; };
076E640D2BF30A9200681536 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 074695362995C03900CCB7BD /* GameController.framework */; };
076E640E2BF30AA200681536 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 070A883F2A4E7A1B003161C0 /* OpenAL.framework */; };
Expand Down Expand Up @@ -454,6 +457,7 @@
074695362995C03900CCB7BD /* GameController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameController.framework; path = System/Library/Frameworks/GameController.framework; sourceTree = SDKROOT; };
075650242C488918004C5E7E /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
075650262C48B417004C5E7E /* RetroArchCI.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RetroArchCI.entitlements; sourceTree = "<group>"; };
076512612D64E99200E1F6BE /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
0776EF3829A005D600AF0237 /* Steam.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Steam.xcconfig; sourceTree = "<group>"; };
0790F6782BF282B400AA58C9 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Media.xcassets; path = OSX/Media.xcassets; sourceTree = "<group>"; };
0795A8C6299A095300D5035D /* CoreHaptics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreHaptics.framework; path = System/Library/Frameworks/CoreHaptics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -529,6 +533,7 @@
0720995429B1258C001642BB /* MetalKit.framework in Frameworks */,
0720995529B1258C001642BB /* libz.dylib in Frameworks */,
070A88412A4E7A24003161C0 /* OpenAL.framework in Frameworks */,
076512642D64E9A000E1F6BE /* CoreLocation.framework in Frameworks */,
0720995629B1258C001642BB /* CoreAudio.framework in Frameworks */,
0720995729B1258C001642BB /* AudioUnit.framework in Frameworks */,
0720995829B1258C001642BB /* AppKit.framework in Frameworks */,
Expand All @@ -552,6 +557,7 @@
07097FFC2D60F4D00021608F /* CoreMIDI.framework in Frameworks */,
07F2BBDD2BE83A4700FD1295 /* libz.dylib in Frameworks */,
07F2BBDE2BE83A4700FD1295 /* OpenAL.framework in Frameworks */,
076512632D64E99A00E1F6BE /* CoreLocation.framework in Frameworks */,
07F2BBDF2BE83A4700FD1295 /* CoreAudio.framework in Frameworks */,
07F2BBE02BE83A4700FD1295 /* AudioUnit.framework in Frameworks */,
07D851CD2CAF06E2005097EA /* CloudKit.framework in Frameworks */,
Expand All @@ -576,6 +582,7 @@
075650252C488918004C5E7E /* CloudKit.framework in Frameworks */,
5061C8A41AE47E510080AE14 /* libz.dylib in Frameworks */,
070A88402A4E7A1B003161C0 /* OpenAL.framework in Frameworks */,
076512622D64E99200E1F6BE /* CoreLocation.framework in Frameworks */,
84DD5EA91A89E4BE007336C1 /* CoreAudio.framework in Frameworks */,
84DD5EB31A89E6C0007336C1 /* AudioUnit.framework in Frameworks */,
84DD5EA31A89E2AA007336C1 /* AppKit.framework in Frameworks */,
Expand Down Expand Up @@ -1252,6 +1259,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
076512612D64E99200E1F6BE /* CoreLocation.framework */,
07097FFA2D60F4C80021608F /* CoreMIDI.framework */,
075650242C488918004C5E7E /* CloudKit.framework */,
070A883F2A4E7A1B003161C0 /* OpenAL.framework */,
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>RetroArch uses the local network to find local Netplay participants.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Some cores can use location.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Some cores are able to provide microphone input to games.</string>
<key>NSUserActivityTypes</key>
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/tvOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<string>public.app-category.games</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Some cores can use location.</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
Expand Down
3 changes: 3 additions & 0 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ static bool init_location(
const char *loc_drv,
bool verbosity_enabled)
{
if (!location_st->driver || !location_st->driver->init)
return false;

/* Resource leaks will follow if location
interface is initialized twice. */
if (!location_st->data)
Expand Down
2 changes: 1 addition & 1 deletion runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
if (sys_info)
sys_info->location_cb = *cb;

loc_st->active = false;
loc_st->active = true;
break;
}

Expand Down

0 comments on commit 8bf7e76

Please sign in to comment.