Skip to content

Commit 8bf7e76

Browse files
authored
apple: enable corelocation location driver (#17595)
1 parent d818cb8 commit 8bf7e76

File tree

10 files changed

+50
-7
lines changed

10 files changed

+50
-7
lines changed

griffin/griffin.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,6 @@ LOCATION
839839
============================================================ */
840840
#if defined(ANDROID)
841841
#include "../location/drivers/android.c"
842-
#elif defined(HAVE_CORELOCATION)
843-
#include "../location/drivers/corelocation.m"
844842
#endif
845843

846844
/*============================================================

griffin/griffin_objc.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
#include "../audio/drivers/coreaudio3.m"
6262
#endif
6363

64+
#ifdef HAVE_CORELOCATION
65+
#include "../location/drivers/corelocation.m"
66+
#endif
67+
6468
#if defined(HAVE_DISCORD)
6569
#include "../deps/discord-rpc/src/discord_register_osx.m"
6670
#endif

location/drivers/corelocation.m

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@ - (instancetype)init {
4747
}
4848

4949
- (void)requestAuthorization {
50-
if (_locationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined) {
50+
CLAuthorizationStatus status;
51+
if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *))
52+
status = [_locationManager authorizationStatus];
53+
else
54+
status = [CLLocationManager authorizationStatus];
55+
56+
if (status == kCLAuthorizationStatusNotDetermined)
5157
[_locationManager requestWhenInUseAuthorization];
52-
}
58+
else
59+
[self locationManager:_locationManager didChangeAuthorizationStatus:status];
5360
}
5461

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

6673
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
67-
self.authorized = (status == kCLAuthorizationStatusAuthorizedWhenInUse ||
68-
status == kCLAuthorizationStatusAuthorizedAlways);
74+
#if TARGET_OS_OSX
75+
if (@available(macOS 10.12, *))
76+
self.authorized = (status == kCLAuthorizationStatusAuthorizedAlways);
77+
#elif TARGET_OS_IPHONE
78+
if (@available(iOS 8.0, tvOS 9.0, *))
79+
self.authorized = (status == kCLAuthorizationStatusAuthorizedWhenInUse ||
80+
status == kCLAuthorizationStatusAuthorizedAlways);
81+
#endif
82+
#if !TARGET_OS_TV
83+
if (self.authorized)
84+
[_locationManager startUpdatingLocation];
85+
#endif
6986
}
7087

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

138+
#if TARGET_OS_TV
139+
CLLocation *location = [corelocation->manager.locationManager location];
140+
*lat = location.coordinate.latitude;
141+
*lon = location.coordinate.longitude;
142+
#else
121143
*lat = corelocation->manager.latitude;
122144
*lon = corelocation->manager.longitude;
145+
#endif
123146
*horiz_accuracy = 0.0; // CoreLocation doesn't provide this directly
124147
*vert_accuracy = 0.0; // CoreLocation doesn't provide this directly
125148
return true;

pkg/apple/BaseConfig.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ OTHER_CFLAGS = $(inherited) -DHAVE_CLOUDSYNC
2121
OTHER_CFLAGS = $(inherited) -DHAVE_COCOA_METAL
2222
OTHER_CFLAGS = $(inherited) -DHAVE_CONFIGFILE
2323
OTHER_CFLAGS = $(inherited) -DHAVE_COREAUDIO
24+
OTHER_CFLAGS = $(inherited) -DHAVE_CORELOCATION
2425
OTHER_CFLAGS = $(inherited) -DHAVE_DR_FLAC
2526
OTHER_CFLAGS = $(inherited) -DHAVE_DR_MP3
2627
OTHER_CFLAGS = $(inherited) -DHAVE_DSP_FILTER

pkg/apple/OSX/Info_Metal.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
<true/>
6565
<key>NSHumanReadableCopyright</key>
6666
<string>Copyright © 2024 RetroArch. All rights reserved.</string>
67+
<key>NSLocationWhenInUseUsageDescription</key>
68+
<string>Some cores can use location.</string>
6769
<key>NSMainNibFile</key>
6870
<string>MainMenu_Metal</string>
6971
<key>NSMicrophoneUsageDescription</key>

pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
072976DD296284F600D6E00C /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 072976DC296284F600D6E00C /* OpenGL.framework */; };
7070
0746953A2997393000CCB7BD /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 074695362995C03900CCB7BD /* GameController.framework */; };
7171
075650252C488918004C5E7E /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 075650242C488918004C5E7E /* CloudKit.framework */; };
72+
076512622D64E99200E1F6BE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076512612D64E99200E1F6BE /* CoreLocation.framework */; };
73+
076512632D64E99A00E1F6BE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076512612D64E99200E1F6BE /* CoreLocation.framework */; };
74+
076512642D64E9A000E1F6BE /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076512612D64E99200E1F6BE /* CoreLocation.framework */; };
7275
076E640C2BF30A7A00681536 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0795A8C6299A095300D5035D /* CoreHaptics.framework */; };
7376
076E640D2BF30A9200681536 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 074695362995C03900CCB7BD /* GameController.framework */; };
7477
076E640E2BF30AA200681536 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 070A883F2A4E7A1B003161C0 /* OpenAL.framework */; };
@@ -454,6 +457,7 @@
454457
074695362995C03900CCB7BD /* GameController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameController.framework; path = System/Library/Frameworks/GameController.framework; sourceTree = SDKROOT; };
455458
075650242C488918004C5E7E /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
456459
075650262C48B417004C5E7E /* RetroArchCI.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RetroArchCI.entitlements; sourceTree = "<group>"; };
460+
076512612D64E99200E1F6BE /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
457461
0776EF3829A005D600AF0237 /* Steam.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Steam.xcconfig; sourceTree = "<group>"; };
458462
0790F6782BF282B400AA58C9 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Media.xcassets; path = OSX/Media.xcassets; sourceTree = "<group>"; };
459463
0795A8C6299A095300D5035D /* CoreHaptics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreHaptics.framework; path = System/Library/Frameworks/CoreHaptics.framework; sourceTree = SDKROOT; };
@@ -529,6 +533,7 @@
529533
0720995429B1258C001642BB /* MetalKit.framework in Frameworks */,
530534
0720995529B1258C001642BB /* libz.dylib in Frameworks */,
531535
070A88412A4E7A24003161C0 /* OpenAL.framework in Frameworks */,
536+
076512642D64E9A000E1F6BE /* CoreLocation.framework in Frameworks */,
532537
0720995629B1258C001642BB /* CoreAudio.framework in Frameworks */,
533538
0720995729B1258C001642BB /* AudioUnit.framework in Frameworks */,
534539
0720995829B1258C001642BB /* AppKit.framework in Frameworks */,
@@ -552,6 +557,7 @@
552557
07097FFC2D60F4D00021608F /* CoreMIDI.framework in Frameworks */,
553558
07F2BBDD2BE83A4700FD1295 /* libz.dylib in Frameworks */,
554559
07F2BBDE2BE83A4700FD1295 /* OpenAL.framework in Frameworks */,
560+
076512632D64E99A00E1F6BE /* CoreLocation.framework in Frameworks */,
555561
07F2BBDF2BE83A4700FD1295 /* CoreAudio.framework in Frameworks */,
556562
07F2BBE02BE83A4700FD1295 /* AudioUnit.framework in Frameworks */,
557563
07D851CD2CAF06E2005097EA /* CloudKit.framework in Frameworks */,
@@ -576,6 +582,7 @@
576582
075650252C488918004C5E7E /* CloudKit.framework in Frameworks */,
577583
5061C8A41AE47E510080AE14 /* libz.dylib in Frameworks */,
578584
070A88402A4E7A1B003161C0 /* OpenAL.framework in Frameworks */,
585+
076512622D64E99200E1F6BE /* CoreLocation.framework in Frameworks */,
579586
84DD5EA91A89E4BE007336C1 /* CoreAudio.framework in Frameworks */,
580587
84DD5EB31A89E6C0007336C1 /* AudioUnit.framework in Frameworks */,
581588
84DD5EA31A89E2AA007336C1 /* AppKit.framework in Frameworks */,
@@ -1252,6 +1259,7 @@
12521259
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
12531260
isa = PBXGroup;
12541261
children = (
1262+
076512612D64E99200E1F6BE /* CoreLocation.framework */,
12551263
07097FFA2D60F4C80021608F /* CoreMIDI.framework */,
12561264
075650242C488918004C5E7E /* CloudKit.framework */,
12571265
070A883F2A4E7A1B003161C0 /* OpenAL.framework */,

pkg/apple/iOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
</array>
9393
<key>NSLocalNetworkUsageDescription</key>
9494
<string>RetroArch uses the local network to find local Netplay participants.</string>
95+
<key>NSLocationWhenInUseUsageDescription</key>
96+
<string>Some cores can use location.</string>
9597
<key>NSMicrophoneUsageDescription</key>
9698
<string>Some cores are able to provide microphone input to games.</string>
9799
<key>NSUserActivityTypes</key>

pkg/apple/tvOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
<string>public.app-category.games</string>
8383
<key>LSRequiresIPhoneOS</key>
8484
<true/>
85+
<key>NSLocationWhenInUseUsageDescription</key>
86+
<string>Some cores can use location.</string>
8587
<key>UIRequiredDeviceCapabilities</key>
8688
<array>
8789
<string>arm64</string>

retroarch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ static bool init_location(
481481
const char *loc_drv,
482482
bool verbosity_enabled)
483483
{
484+
if (!location_st->driver || !location_st->driver->init)
485+
return false;
486+
484487
/* Resource leaks will follow if location
485488
interface is initialized twice. */
486489
if (!location_st->data)

runloop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
25502550
if (sys_info)
25512551
sys_info->location_cb = *cb;
25522552

2553-
loc_st->active = false;
2553+
loc_st->active = true;
25542554
break;
25552555
}
25562556

0 commit comments

Comments
 (0)