From 8bf7e76f45d49bc0f8e286ba224b120f8f994b95 Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Tue, 18 Feb 2025 22:04:17 -0500 Subject: [PATCH] apple: enable corelocation location driver (#17595) --- griffin/griffin.c | 2 -- griffin/griffin_objc.m | 4 +++ location/drivers/corelocation.m | 31 ++++++++++++++++--- pkg/apple/BaseConfig.xcconfig | 1 + pkg/apple/OSX/Info_Metal.plist | 2 ++ .../RetroArch_Metal.xcodeproj/project.pbxproj | 8 +++++ pkg/apple/iOS/Info.plist | 2 ++ pkg/apple/tvOS/Info.plist | 2 ++ retroarch.c | 3 ++ runloop.c | 2 +- 10 files changed, 50 insertions(+), 7 deletions(-) diff --git a/griffin/griffin.c b/griffin/griffin.c index 9287af7d2c1a..71adf7d03f61 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -839,8 +839,6 @@ LOCATION ============================================================ */ #if defined(ANDROID) #include "../location/drivers/android.c" -#elif defined(HAVE_CORELOCATION) -#include "../location/drivers/corelocation.m" #endif /*============================================================ diff --git a/griffin/griffin_objc.m b/griffin/griffin_objc.m index 68c6ac6e477f..c6ce46992091 100644 --- a/griffin/griffin_objc.m +++ b/griffin/griffin_objc.m @@ -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 diff --git a/location/drivers/corelocation.m b/location/drivers/corelocation.m index 0e2a6d30c709..2f9d2622e214 100644 --- a/location/drivers/corelocation.m +++ b/location/drivers/corelocation.m @@ -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 *)locations { @@ -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 @@ -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; diff --git a/pkg/apple/BaseConfig.xcconfig b/pkg/apple/BaseConfig.xcconfig index ffe2507debba..c570f53e1d03 100644 --- a/pkg/apple/BaseConfig.xcconfig +++ b/pkg/apple/BaseConfig.xcconfig @@ -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 diff --git a/pkg/apple/OSX/Info_Metal.plist b/pkg/apple/OSX/Info_Metal.plist index a0b668237ee6..e6aa39b9c21e 100644 --- a/pkg/apple/OSX/Info_Metal.plist +++ b/pkg/apple/OSX/Info_Metal.plist @@ -64,6 +64,8 @@ NSHumanReadableCopyright Copyright © 2024 RetroArch. All rights reserved. + NSLocationWhenInUseUsageDescription + Some cores can use location. NSMainNibFile MainMenu_Metal NSMicrophoneUsageDescription diff --git a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj index 2b5224c438bc..89a4aff5b4fc 100644 --- a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj +++ b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; + 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 = ""; }; 0790F6782BF282B400AA58C9 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Media.xcassets; path = OSX/Media.xcassets; sourceTree = ""; }; 0795A8C6299A095300D5035D /* CoreHaptics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreHaptics.framework; path = System/Library/Frameworks/CoreHaptics.framework; sourceTree = SDKROOT; }; @@ -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 */, @@ -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 */, @@ -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 */, @@ -1252,6 +1259,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + 076512612D64E99200E1F6BE /* CoreLocation.framework */, 07097FFA2D60F4C80021608F /* CoreMIDI.framework */, 075650242C488918004C5E7E /* CloudKit.framework */, 070A883F2A4E7A1B003161C0 /* OpenAL.framework */, diff --git a/pkg/apple/iOS/Info.plist b/pkg/apple/iOS/Info.plist index d72be980e565..1c369a991d99 100644 --- a/pkg/apple/iOS/Info.plist +++ b/pkg/apple/iOS/Info.plist @@ -92,6 +92,8 @@ NSLocalNetworkUsageDescription RetroArch uses the local network to find local Netplay participants. + NSLocationWhenInUseUsageDescription + Some cores can use location. NSMicrophoneUsageDescription Some cores are able to provide microphone input to games. NSUserActivityTypes diff --git a/pkg/apple/tvOS/Info.plist b/pkg/apple/tvOS/Info.plist index 710996f691e7..bc23043ee1ff 100644 --- a/pkg/apple/tvOS/Info.plist +++ b/pkg/apple/tvOS/Info.plist @@ -82,6 +82,8 @@ public.app-category.games LSRequiresIPhoneOS + NSLocationWhenInUseUsageDescription + Some cores can use location. UIRequiredDeviceCapabilities arm64 diff --git a/retroarch.c b/retroarch.c index 92bae1965e8c..ea135e5ef037 100644 --- a/retroarch.c +++ b/retroarch.c @@ -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) diff --git a/runloop.c b/runloop.c index aa4158bec2d8..558d1dffc37f 100644 --- a/runloop.c +++ b/runloop.c @@ -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; }