expo-location 58.0.11 → 58.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/location/next/LocationModuleNext.kt +2 -2
- package/android/src/main/java/expo/modules/location/next/LocationPermissions.kt +1 -1
- package/android/src/main/java/expo/modules/location/next/LocationRecords.kt +1 -1
- package/android/src/main/java/expo/modules/location/next/WatchPosition.kt +11 -2
- package/build/Location.types.d.ts +4 -1
- package/build/Location.types.js.map +1 -1
- package/build/next/Location.d.ts +1 -0
- package/build/next/Location.js +3 -0
- package/build/next/Location.js.map +1 -0
- package/build/next/index.d.ts +3 -0
- package/build/next/index.js +5 -0
- package/build/next/index.js.map +1 -0
- package/build/next/js/LocationProvider.d.ts +9 -0
- package/build/next/js/LocationProvider.js +20 -0
- package/build/next/js/LocationProvider.js.map +1 -0
- package/build/next/js/LocationUpdatesHandle.d.ts +15 -0
- package/build/next/js/LocationUpdatesHandle.js +39 -0
- package/build/next/js/LocationUpdatesHandle.js.map +1 -0
- package/build/next/js/Permissions.d.ts +7 -0
- package/build/next/js/Permissions.js +24 -0
- package/build/next/js/Permissions.js.map +1 -0
- package/build/next/js/PositionWatchHandle.d.ts +16 -0
- package/build/next/js/PositionWatchHandle.js +50 -0
- package/build/next/js/PositionWatchHandle.js.map +1 -0
- package/build/next/js/getPosition.d.ts +2 -0
- package/build/next/js/getPosition.js +6 -0
- package/build/next/js/getPosition.js.map +1 -0
- package/build/next/js/index.d.ts +6 -0
- package/build/next/js/index.js +8 -0
- package/build/next/js/index.js.map +1 -0
- package/build/next/js/locationServices.d.ts +3 -0
- package/build/next/js/locationServices.js +35 -0
- package/build/next/js/locationServices.js.map +1 -0
- package/build/next/native/NativeLocationModuleNext.d.ts +5 -0
- package/build/next/native/NativeLocationModuleNext.js +7 -0
- package/build/next/native/NativeLocationModuleNext.js.map +1 -0
- package/build/next/native/index.d.ts +5 -0
- package/build/next/native/index.js +3 -0
- package/build/next/native/index.js.map +1 -0
- package/build/next/native/types/NativeLocationModuleNextClass.types.d.ts +21 -0
- package/build/next/native/types/NativeLocationModuleNextClass.types.js +3 -0
- package/build/next/native/types/NativeLocationModuleNextClass.types.js.map +1 -0
- package/build/next/native/types/NativeLocationProviderClass.types.d.ts +8 -0
- package/build/next/native/types/NativeLocationProviderClass.types.js +3 -0
- package/build/next/native/types/NativeLocationProviderClass.types.js.map +1 -0
- package/build/next/native/types/NativeLocationUpdatesHandleClass.types.d.ts +8 -0
- package/build/next/native/types/NativeLocationUpdatesHandleClass.types.js +3 -0
- package/build/next/native/types/NativeLocationUpdatesHandleClass.types.js.map +1 -0
- package/build/next/native/types/NativePositionWatchHandleClass.types.d.ts +12 -0
- package/build/next/native/types/NativePositionWatchHandleClass.types.js +3 -0
- package/build/next/native/types/NativePositionWatchHandleClass.types.js.map +1 -0
- package/build/next/types/LocationProvider.types.d.ts +1 -0
- package/build/next/types/LocationProvider.types.js +3 -0
- package/build/next/types/LocationProvider.types.js.map +1 -0
- package/build/next/types/Permissions.types.d.ts +22 -0
- package/build/next/types/Permissions.types.js +19 -0
- package/build/next/types/Permissions.types.js.map +1 -0
- package/build/next/types/Position.types.d.ts +55 -0
- package/build/next/types/Position.types.js +11 -0
- package/build/next/types/Position.types.js.map +1 -0
- package/build/next/types/index.d.ts +3 -0
- package/build/next/types/index.js +5 -0
- package/build/next/types/index.js.map +1 -0
- package/expo-module.config.json +1 -1
- package/ios/EXLocation.m +1 -0
- package/ios/ExpoLocation.podspec +9 -0
- package/ios/LocationUtils.swift +3 -1
- package/ios/next/LocationModuleNext.swift +110 -0
- package/ios/next/LocationNextExceptions.swift +118 -0
- package/ios/next/LocationUpdatesHandle/LocationUpdatesHandle.swift +52 -0
- package/ios/next/LocationUpdatesHandle/LocationUpdatesTaskConsumer.swift +40 -0
- package/ios/next/LocationUpdatesHandle/LocationUpdatesTaskOptions.swift +19 -0
- package/ios/next/LocationUpdatesHandle/SignificantLocationChangeMonitor.swift +20 -0
- package/ios/next/Permissions/BackgroundPermissionsRequester.swift +34 -0
- package/ios/next/Permissions/CLLocationManager+MainThread.swift +10 -0
- package/ios/next/Permissions/ForegroundPermissionsRequester.swift +38 -0
- package/ios/next/Permissions/LocationAccessGuard.swift +21 -0
- package/ios/next/Permissions/LocationAccuracyAuthorization.swift +9 -0
- package/ios/next/Permissions/LocationAccuracyOption.swift +6 -0
- package/ios/next/Permissions/LocationAuthorizationScope.swift +16 -0
- package/ios/next/Permissions/LocationManagerAlwaysAuthorizationRequest.swift +109 -0
- package/ios/next/Permissions/LocationPermissionKind.swift +26 -0
- package/ios/next/Permissions/LocationPermissionResponse.swift +51 -0
- package/ios/next/Permissions/LocationPermissionsDelegate.swift +85 -0
- package/ios/next/Permissions/LocationPermissionsRequester.swift +96 -0
- package/ios/next/Permissions/LocationPlistKeys.swift +10 -0
- package/ios/next/Permissions/PermissionsRequestOptions.swift +5 -0
- package/ios/next/Permissions/TemporaryFullAccuracyPlistKeys.swift +13 -0
- package/ios/next/Permissions/TemporaryFullAccuracyRequester.swift +28 -0
- package/ios/next/Position/Coordinates.swift +7 -0
- package/ios/next/Position/GetPositionOptions.swift +7 -0
- package/ios/next/Position/LocationUpdateDiagnostics.swift +41 -0
- package/ios/next/Position/Position.swift +43 -0
- package/ios/next/Position/PositionRequester.swift +55 -0
- package/ios/next/Position/PositionUpdatesCompatibilitySource.swift +43 -0
- package/ios/next/Position/PositionUpdatesLiveSource.swift +46 -0
- package/ios/next/Position/PositionUpdatesSource.swift +40 -0
- package/ios/next/Position/PositionUpdatesSubscription.swift +85 -0
- package/ios/next/PositionWatcher/PositionWatchStatus.swift +9 -0
- package/ios/next/PositionWatcher/PositionWatcher.swift +143 -0
- package/ios/next/Profile.swift +60 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.11/expo.modules.location-58.0.11-sources.jar → 58.0.13/expo.modules.location-58.0.13-sources.jar} +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13-sources.jar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.aar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.11/expo.modules.location-58.0.11.module → 58.0.13/expo.modules.location-58.0.13.module} +22 -22
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.11/expo.modules.location-58.0.11.pom → 58.0.13/expo.modules.location-58.0.13.pom} +1 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha512 +1 -0
- package/package.json +33 -4
- package/plugin/build/withLocation.d.ts +18 -0
- package/plugin/build/withLocation.js +28 -1
- package/plugin/build/withLocation.js.map +1 -1
- package/plugin/src/withLocation.ts +52 -0
- package/src/Location.types.ts +4 -1
- package/src/next/Location.ts +12 -0
- package/src/next/index.ts +28 -0
- package/src/next/js/LocationProvider.ts +28 -0
- package/src/next/js/LocationUpdatesHandle.ts +60 -0
- package/src/next/js/Permissions.ts +34 -0
- package/src/next/js/PositionWatchHandle.ts +75 -0
- package/src/next/js/getPosition.ts +6 -0
- package/src/next/js/index.ts +21 -0
- package/src/next/js/locationServices.ts +38 -0
- package/src/next/native/NativeLocationModuleNext.ts +9 -0
- package/src/next/native/index.ts +10 -0
- package/src/next/native/types/NativeLocationModuleNextClass.types.ts +34 -0
- package/src/next/native/types/NativeLocationProviderClass.types.ts +12 -0
- package/src/next/native/types/NativeLocationUpdatesHandleClass.types.ts +9 -0
- package/src/next/native/types/NativePositionWatchHandleClass.types.ts +14 -0
- package/src/next/types/LocationProvider.types.ts +1 -0
- package/src/next/types/Permissions.types.ts +27 -0
- package/src/next/types/Position.types.ts +58 -0
- package/src/next/types/index.ts +3 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11-sources.jar.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11-sources.jar.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11-sources.jar.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11-sources.jar.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.aar.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.aar.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.aar.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.aar.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.module.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.module.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.module.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.module.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.pom.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.pom.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.pom.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.11/expo.modules.location-58.0.11.pom.sha512 +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
|
|
3
|
+
enum LocationAuthorizationScope: String {
|
|
4
|
+
case whenInUse, always, notGranted
|
|
5
|
+
|
|
6
|
+
static func from(_ systemStatus: CLAuthorizationStatus) -> LocationAuthorizationScope {
|
|
7
|
+
switch systemStatus {
|
|
8
|
+
case .authorizedWhenInUse:
|
|
9
|
+
return .whenInUse
|
|
10
|
+
case .authorizedAlways:
|
|
11
|
+
return .always
|
|
12
|
+
default:
|
|
13
|
+
return .notGranted
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
final class LocationManagerAlwaysAuthorizationRequest: NSObject, CLLocationManagerDelegate {
|
|
5
|
+
private static let alwaysAuthorizationSelector = NSSelectorFromString(["request", "AlwaysAuthorization"].joined())
|
|
6
|
+
private static let noDialogTimeout: Duration = .seconds(1.5)
|
|
7
|
+
|
|
8
|
+
private let locationManager: CLLocationManager
|
|
9
|
+
private var authorizationChanges: AsyncThrowingStream<Void, Error>.Continuation?
|
|
10
|
+
private var beginStatus: CLAuthorizationStatus?
|
|
11
|
+
|
|
12
|
+
init(locationManager: CLLocationManager) {
|
|
13
|
+
self.locationManager = locationManager
|
|
14
|
+
super.init()
|
|
15
|
+
locationManager.delegate = self
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@MainActor
|
|
19
|
+
func request() async throws {
|
|
20
|
+
let authorizationChanges = makeAuthorizationChanges()
|
|
21
|
+
defer {
|
|
22
|
+
self.authorizationChanges?.finish()
|
|
23
|
+
self.authorizationChanges = nil
|
|
24
|
+
}
|
|
25
|
+
let appWillResignActive = NotificationCenter.default.notifications(named: UIApplication.willResignActiveNotification)
|
|
26
|
+
let appDidBecomeActive = NotificationCenter.default.notifications(named: UIApplication.didBecomeActiveNotification)
|
|
27
|
+
let beginStatus = locationManager.authorizationStatus
|
|
28
|
+
self.beginStatus = beginStatus
|
|
29
|
+
let isUpgradeFromWhenInUse = beginStatus == .authorizedWhenInUse
|
|
30
|
+
|
|
31
|
+
try await withThrowingTaskGroup(of: Void.self) { group in
|
|
32
|
+
group.addTask {
|
|
33
|
+
try await Self.waitForAuthorizationChange(authorizationChanges)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if isUpgradeFromWhenInUse {
|
|
37
|
+
group.addTask { @MainActor in
|
|
38
|
+
await Self.waitForDialogToClose(
|
|
39
|
+
appWillResignActive: appWillResignActive,
|
|
40
|
+
appDidBecomeActive: appDidBecomeActive
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
locationManager.perform(Self.alwaysAuthorizationSelector)
|
|
46
|
+
|
|
47
|
+
try await group.next()
|
|
48
|
+
group.cancelAll()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private func makeAuthorizationChanges() -> AsyncThrowingStream<Void, Error> {
|
|
53
|
+
return AsyncThrowingStream { continuation in
|
|
54
|
+
self.authorizationChanges = continuation
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private static func waitForAuthorizationChange(_ changes: AsyncThrowingStream<Void, Error>) async throws {
|
|
59
|
+
for try await _ in changes {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@MainActor
|
|
65
|
+
private static func waitForDialogToClose(
|
|
66
|
+
appWillResignActive: NotificationCenter.Notifications,
|
|
67
|
+
appDidBecomeActive: NotificationCenter.Notifications
|
|
68
|
+
) async {
|
|
69
|
+
let dialogDidOpen = await receivedNotification(from: appWillResignActive, within: noDialogTimeout)
|
|
70
|
+
guard dialogDidOpen else {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
for await _ in appDidBecomeActive {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private static func receivedNotification(
|
|
79
|
+
from notifications: NotificationCenter.Notifications,
|
|
80
|
+
within timeout: Duration
|
|
81
|
+
) async -> Bool {
|
|
82
|
+
return await withTaskGroup(of: Bool.self) { group in
|
|
83
|
+
group.addTask {
|
|
84
|
+
for await _ in notifications {
|
|
85
|
+
return true
|
|
86
|
+
}
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
group.addTask {
|
|
90
|
+
try? await Task.sleep(for: timeout)
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
let firstResult = await group.next() ?? false
|
|
94
|
+
group.cancelAll()
|
|
95
|
+
return firstResult
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
|
100
|
+
guard manager.authorizationStatus != beginStatus else {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
authorizationChanges?.yield(())
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
|
|
107
|
+
authorizationChanges?.finish(throwing: error)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
struct LocationPermissionKind {
|
|
5
|
+
let plistKeys: [String]
|
|
6
|
+
let requesterClass: EXPermissionsRequester.Type
|
|
7
|
+
let grantingStatuses: [CLAuthorizationStatus]
|
|
8
|
+
let permissionName: String
|
|
9
|
+
let requestFunctionName: String
|
|
10
|
+
|
|
11
|
+
static let foreground = LocationPermissionKind(
|
|
12
|
+
plistKeys: [LocationPlistKeys.whenInUse],
|
|
13
|
+
requesterClass: ForegroundPermissionsRequester.self,
|
|
14
|
+
grantingStatuses: [.authorizedWhenInUse, .authorizedAlways],
|
|
15
|
+
permissionName: "LOCATION_FOREGROUND",
|
|
16
|
+
requestFunctionName: "requestForegroundPermissions"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
static let background = LocationPermissionKind(
|
|
20
|
+
plistKeys: [LocationPlistKeys.whenInUse, LocationPlistKeys.alwaysAndWhenInUse],
|
|
21
|
+
requesterClass: BackgroundPermissionsRequester.self,
|
|
22
|
+
grantingStatuses: [.authorizedAlways],
|
|
23
|
+
permissionName: "LOCATION_BACKGROUND",
|
|
24
|
+
requestFunctionName: "requestBackgroundPermissions"
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
struct LocationPermissionResponse {
|
|
5
|
+
let status: EXPermissionStatus
|
|
6
|
+
let scope: LocationAuthorizationScope
|
|
7
|
+
let accuracy: LocationAccuracyAuthorization
|
|
8
|
+
|
|
9
|
+
static let denied = LocationPermissionResponse(
|
|
10
|
+
status: EXPermissionStatusDenied,
|
|
11
|
+
scope: .notGranted,
|
|
12
|
+
accuracy: .notGranted
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
static let undetermined = LocationPermissionResponse(
|
|
16
|
+
status: EXPermissionStatusUndetermined,
|
|
17
|
+
scope: .notGranted,
|
|
18
|
+
accuracy: .notGranted
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
static func whenInUse(
|
|
22
|
+
status: EXPermissionStatus = EXPermissionStatusGranted,
|
|
23
|
+
accuracy: CLAccuracyAuthorization
|
|
24
|
+
) -> LocationPermissionResponse {
|
|
25
|
+
return LocationPermissionResponse(
|
|
26
|
+
status: status,
|
|
27
|
+
scope: .whenInUse,
|
|
28
|
+
accuracy: .from(accuracy)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static func always(accuracy: CLAccuracyAuthorization) -> LocationPermissionResponse {
|
|
33
|
+
return LocationPermissionResponse(
|
|
34
|
+
status: EXPermissionStatusGranted,
|
|
35
|
+
scope: .always,
|
|
36
|
+
accuracy: .from(accuracy)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var isUndetermined: Bool {
|
|
41
|
+
return status == EXPermissionStatusUndetermined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func toDictionary() -> [AnyHashable: Any] {
|
|
45
|
+
return [
|
|
46
|
+
"status": status.rawValue,
|
|
47
|
+
"scope": scope.rawValue,
|
|
48
|
+
"accuracy": accuracy.rawValue
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
final class LocationPermissionsDelegate {
|
|
4
|
+
private weak var appContext: AppContext?
|
|
5
|
+
private lazy var fullAccuracyRequester = TemporaryFullAccuracyRequester()
|
|
6
|
+
|
|
7
|
+
init(appContext: AppContext?) {
|
|
8
|
+
self.appContext = appContext
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
func registerRequesters() {
|
|
12
|
+
EXPermissionsMethodsDelegate.register(
|
|
13
|
+
[
|
|
14
|
+
ForegroundPermissionsRequester(),
|
|
15
|
+
BackgroundPermissionsRequester()
|
|
16
|
+
],
|
|
17
|
+
withPermissionsManager: appContext?.permissions
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func getForegroundPermissions(_ promise: Promise) throws {
|
|
22
|
+
try getPermissions(.foreground, promise)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func getBackgroundPermissions(_ promise: Promise) throws {
|
|
26
|
+
try getPermissions(.background, promise)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func requestForegroundPermissions(options: PermissionsRequestOptions, _ promise: Promise) throws {
|
|
30
|
+
try requestAndRaiseAccuracyIfNeeded(.foreground, options: options, promise)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func requestBackgroundPermissions(options: PermissionsRequestOptions, _ promise: Promise) throws {
|
|
34
|
+
try requestAndRaiseAccuracyIfNeeded(.background, options: options, promise)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private func getPermissions(_ kind: LocationPermissionKind, _ promise: Promise) throws {
|
|
38
|
+
guard let permissions = appContext?.permissions else {
|
|
39
|
+
throw PermissionsModuleUnavailable()
|
|
40
|
+
}
|
|
41
|
+
permissions.getPermissionUsingRequesterClass(
|
|
42
|
+
kind.requesterClass,
|
|
43
|
+
resolve: promise.legacyResolver,
|
|
44
|
+
reject: promise.legacyRejecter
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private func requestAndRaiseAccuracyIfNeeded(
|
|
49
|
+
_ kind: LocationPermissionKind,
|
|
50
|
+
options: PermissionsRequestOptions,
|
|
51
|
+
_ promise: Promise
|
|
52
|
+
) throws {
|
|
53
|
+
guard let permissions = appContext?.permissions else {
|
|
54
|
+
throw PermissionsModuleUnavailable()
|
|
55
|
+
}
|
|
56
|
+
let purposeKey = fullAccuracyPurposeKey(for: options)
|
|
57
|
+
|
|
58
|
+
permissions.askForPermission(
|
|
59
|
+
usingRequesterClass: kind.requesterClass,
|
|
60
|
+
resolve: { result in
|
|
61
|
+
guard let purposeKey else {
|
|
62
|
+
promise.resolve(result)
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
Task { @MainActor in
|
|
66
|
+
await self.fullAccuracyRequester.raiseIfReduced(purposeKey: purposeKey, for: kind)
|
|
67
|
+
permissions.getPermissionUsingRequesterClass(
|
|
68
|
+
kind.requesterClass,
|
|
69
|
+
resolve: promise.legacyResolver,
|
|
70
|
+
reject: promise.legacyRejecter
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
reject: promise.legacyRejecter
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private func fullAccuracyPurposeKey(for options: PermissionsRequestOptions) -> String? {
|
|
79
|
+
let purposeKey = TemporaryFullAccuracyPlistKeys.purposeKey
|
|
80
|
+
guard options.accuracy == .full, TemporaryFullAccuracyPlistKeys.containsPurposeKey(purposeKey) else {
|
|
81
|
+
return nil
|
|
82
|
+
}
|
|
83
|
+
return purposeKey
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
class LocationPermissionsRequester: NSObject, EXPermissionsRequester {
|
|
5
|
+
let kind: LocationPermissionKind
|
|
6
|
+
lazy var locationManager = CLLocationManager.makeOnMainThread()
|
|
7
|
+
// Only accessed from the main thread, so it does not need to be synchronized
|
|
8
|
+
private var pendingRequests: [(resolve: EXPromiseResolveBlock, reject: EXPromiseRejectBlock)] = []
|
|
9
|
+
|
|
10
|
+
init(kind: LocationPermissionKind) {
|
|
11
|
+
self.kind = kind
|
|
12
|
+
super.init()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class func permissionType() -> String {
|
|
16
|
+
preconditionFailure("Subclasses must override permissionType()")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func getPermissions() -> [AnyHashable: Any] {
|
|
20
|
+
return currentResponse().toDictionary()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func requestPermissions(
|
|
24
|
+
resolver resolve: @escaping EXPromiseResolveBlock,
|
|
25
|
+
rejecter reject: @escaping EXPromiseRejectBlock
|
|
26
|
+
) {
|
|
27
|
+
if let missingKey = LocationPlistKeys.firstMissing(in: kind.plistKeys) {
|
|
28
|
+
let exception = MissingPlistKeyException(missingKey)
|
|
29
|
+
reject(exception.code, exception.description, exception)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let response = currentResponse()
|
|
34
|
+
if !response.isUndetermined {
|
|
35
|
+
resolve(response.toDictionary())
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Task { @MainActor [weak self] in
|
|
40
|
+
guard let self else {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
let isPromptAlreadyRequested = !pendingRequests.isEmpty
|
|
44
|
+
pendingRequests.append((resolve, reject))
|
|
45
|
+
if !isPromptAlreadyRequested {
|
|
46
|
+
await requestFromSystem()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@MainActor
|
|
52
|
+
func requestFromSystem() async {
|
|
53
|
+
preconditionFailure("Subclasses must override requestFromSystem()")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
func whenInUseResponse(accuracy: CLAccuracyAuthorization) -> LocationPermissionResponse {
|
|
57
|
+
return LocationPermissionResponse.whenInUse(accuracy: accuracy)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
final func resolvePendingRequests() {
|
|
61
|
+
let response = getPermissions()
|
|
62
|
+
let requests = pendingRequests
|
|
63
|
+
pendingRequests = []
|
|
64
|
+
for request in requests {
|
|
65
|
+
request.resolve(response)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
final func rejectPendingRequests(with error: Error) {
|
|
70
|
+
let exception = PermissionRequestFailedException().causedBy(error)
|
|
71
|
+
let requests = pendingRequests
|
|
72
|
+
pendingRequests = []
|
|
73
|
+
for request in requests {
|
|
74
|
+
request.reject(exception.code, exception.description, exception)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
final func currentResponse() -> LocationPermissionResponse {
|
|
79
|
+
guard LocationPlistKeys.firstMissing(in: kind.plistKeys) == nil else {
|
|
80
|
+
return LocationPermissionResponse.denied
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
switch locationManager.authorizationStatus {
|
|
84
|
+
case .authorizedWhenInUse:
|
|
85
|
+
return whenInUseResponse(accuracy: locationManager.accuracyAuthorization)
|
|
86
|
+
case .authorizedAlways:
|
|
87
|
+
return LocationPermissionResponse.always(accuracy: locationManager.accuracyAuthorization)
|
|
88
|
+
case .denied, .restricted:
|
|
89
|
+
return LocationPermissionResponse.denied
|
|
90
|
+
case .notDetermined:
|
|
91
|
+
return LocationPermissionResponse.undetermined
|
|
92
|
+
@unknown default:
|
|
93
|
+
return LocationPermissionResponse.undetermined
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum LocationPlistKeys {
|
|
4
|
+
static let whenInUse = "NSLocationWhenInUseUsageDescription"
|
|
5
|
+
static let alwaysAndWhenInUse = "NSLocationAlwaysAndWhenInUseUsageDescription"
|
|
6
|
+
|
|
7
|
+
static func firstMissing(in keys: [String]) -> String? {
|
|
8
|
+
return keys.first { Bundle.main.object(forInfoDictionaryKey: $0) == nil }
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum TemporaryFullAccuracyPlistKeys {
|
|
4
|
+
static let purposeDictionary = "NSLocationTemporaryUsageDescriptionDictionary"
|
|
5
|
+
static let purposeKey = "ExpoLocationFullAccuracy"
|
|
6
|
+
|
|
7
|
+
static func containsPurposeKey(_ purposeKey: String) -> Bool {
|
|
8
|
+
guard let dictionary = Bundle.main.object(forInfoDictionaryKey: purposeDictionary) as? [String: Any] else {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
return dictionary[purposeKey] != nil
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
|
|
3
|
+
final class TemporaryFullAccuracyRequester {
|
|
4
|
+
private lazy var manager = CLLocationManager.makeOnMainThread()
|
|
5
|
+
private var pendingRaise: Task<Void, Never>?
|
|
6
|
+
|
|
7
|
+
@MainActor
|
|
8
|
+
func raiseIfReduced(purposeKey: String, for kind: LocationPermissionKind) async {
|
|
9
|
+
if let pendingRaise {
|
|
10
|
+
await pendingRaise.value
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
let isGranted = kind.grantingStatuses.contains(manager.authorizationStatus)
|
|
14
|
+
guard isGranted, manager.accuracyAuthorization == .reducedAccuracy else {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
let task = Task { @MainActor in
|
|
18
|
+
await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) in
|
|
19
|
+
manager.requestTemporaryFullAccuracyAuthorization(withPurposeKey: purposeKey) { _ in
|
|
20
|
+
continuation.resume()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
pendingRaise = task
|
|
25
|
+
await task.value
|
|
26
|
+
pendingRaise = nil
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
struct LocationUpdateDiagnostics {
|
|
5
|
+
let authorizationDenied: Bool
|
|
6
|
+
let authorizationDeniedGlobally: Bool
|
|
7
|
+
let authorizationRestricted: Bool
|
|
8
|
+
let serviceSessionRequired: Bool
|
|
9
|
+
let insufficientlyInUse: Bool
|
|
10
|
+
let locationUnavailable: Bool
|
|
11
|
+
|
|
12
|
+
func unrecoverableFailure() -> Exception? {
|
|
13
|
+
if authorizationRestricted {
|
|
14
|
+
return LocationAuthorizationRestricted()
|
|
15
|
+
}
|
|
16
|
+
if authorizationDeniedGlobally {
|
|
17
|
+
return LocationServicesDisabledGlobally()
|
|
18
|
+
}
|
|
19
|
+
if authorizationDenied {
|
|
20
|
+
return LocationAuthorizationDenied()
|
|
21
|
+
}
|
|
22
|
+
if serviceSessionRequired {
|
|
23
|
+
return LocationServiceSessionRequired()
|
|
24
|
+
}
|
|
25
|
+
return nil
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@available(iOS 18.0, *)
|
|
30
|
+
extension LocationUpdateDiagnostics {
|
|
31
|
+
init(_ update: CLLocationUpdate) {
|
|
32
|
+
self.init(
|
|
33
|
+
authorizationDenied: update.authorizationDenied,
|
|
34
|
+
authorizationDeniedGlobally: update.authorizationDeniedGlobally,
|
|
35
|
+
authorizationRestricted: update.authorizationRestricted,
|
|
36
|
+
serviceSessionRequired: update.serviceSessionRequired,
|
|
37
|
+
insufficientlyInUse: update.insufficientlyInUse,
|
|
38
|
+
locationUnavailable: update.locationUnavailable
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import CoreLocation
|
|
3
|
+
|
|
4
|
+
@Record
|
|
5
|
+
struct Position {
|
|
6
|
+
var coordinates: Coordinates
|
|
7
|
+
var horizontalAccuracy: Double?
|
|
8
|
+
var timestamp: Double
|
|
9
|
+
var altitude: Double?
|
|
10
|
+
var mslAltitude: Double?
|
|
11
|
+
var verticalAccuracy: Double?
|
|
12
|
+
var mocked: Bool
|
|
13
|
+
var heading: Double?
|
|
14
|
+
var headingAccuracy: Double?
|
|
15
|
+
var speed: Double?
|
|
16
|
+
var speedAccuracy: Double?
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
extension Position {
|
|
20
|
+
func toEventPayload() -> [String: Any] {
|
|
21
|
+
var payload = toDictionary()
|
|
22
|
+
payload["coordinates"] = coordinates.toDictionary()
|
|
23
|
+
return payload
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
extension CLLocation {
|
|
28
|
+
func toPosition() -> Position {
|
|
29
|
+
return Position(
|
|
30
|
+
coordinates: Coordinates(latitude: coordinate.latitude, longitude: coordinate.longitude),
|
|
31
|
+
horizontalAccuracy: horizontalAccuracy >= 0 ? horizontalAccuracy : nil,
|
|
32
|
+
timestamp: timestamp.timeIntervalSince1970 * 1000,
|
|
33
|
+
altitude: verticalAccuracy >= 0 ? ellipsoidalAltitude : nil,
|
|
34
|
+
mslAltitude: verticalAccuracy >= 0 ? altitude : nil,
|
|
35
|
+
verticalAccuracy: verticalAccuracy >= 0 ? verticalAccuracy : nil,
|
|
36
|
+
mocked: sourceInformation?.isSimulatedBySoftware ?? false,
|
|
37
|
+
heading: course >= 0 ? course : nil,
|
|
38
|
+
headingAccuracy: course >= 0 && courseAccuracy >= 0 ? courseAccuracy : nil,
|
|
39
|
+
speed: speed >= 0 ? speed : nil,
|
|
40
|
+
speedAccuracy: speed >= 0 && speedAccuracy >= 0 ? speedAccuracy : nil
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
final class PositionRequester {
|
|
5
|
+
var liveUpdates: (_ profile: Profile) -> AsyncThrowingStream<CLLocation?, Error> = { PositionUpdatesSource.foreground(for: $0).stream }
|
|
6
|
+
var cachedLocation: () async -> CLLocation? = {
|
|
7
|
+
await MainActor.run { CLLocationManager().location }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
func get(options: GetPositionOptions) async throws -> CLLocation? {
|
|
11
|
+
guard options.timeout >= 0 else {
|
|
12
|
+
throw InvalidLocationTimeoutException()
|
|
13
|
+
}
|
|
14
|
+
guard options.maxCachedAge >= 0 else {
|
|
15
|
+
throw InvalidMaxCachedAgeException()
|
|
16
|
+
}
|
|
17
|
+
let requestedAt = Date()
|
|
18
|
+
if let cached = await cachedLocation(), isRecentEnough(cached, asOf: requestedAt, options: options) {
|
|
19
|
+
return cached
|
|
20
|
+
}
|
|
21
|
+
guard options.timeout > 0 else {
|
|
22
|
+
return await cachedLocation()
|
|
23
|
+
}
|
|
24
|
+
return try await withThrowingTaskGroup(of: CLLocation?.self) { group in
|
|
25
|
+
group.addTask {
|
|
26
|
+
try await self.firstLocation(options: options, requestedAt: requestedAt)
|
|
27
|
+
}
|
|
28
|
+
if options.timeout != .infinity {
|
|
29
|
+
group.addTask {
|
|
30
|
+
try await Task.sleep(for: .seconds(options.timeout))
|
|
31
|
+
return nil
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let location = try await group.next() ?? nil
|
|
35
|
+
group.cancelAll()
|
|
36
|
+
if let location {
|
|
37
|
+
return location
|
|
38
|
+
}
|
|
39
|
+
return await cachedLocation()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private func firstLocation(options: GetPositionOptions, requestedAt: Date) async throws -> CLLocation? {
|
|
44
|
+
for try await location in liveUpdates(options.profile) {
|
|
45
|
+
if let location, isRecentEnough(location, asOf: requestedAt, options: options) {
|
|
46
|
+
return location
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return nil
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private func isRecentEnough(_ location: CLLocation, asOf reference: Date, options: GetPositionOptions) -> Bool {
|
|
53
|
+
reference.timeIntervalSince(location.timestamp) <= options.maxCachedAge
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
|
|
3
|
+
final class PositionUpdatesCompatibilitySource: NSObject, CLLocationManagerDelegate {
|
|
4
|
+
private lazy var manager = CLLocationManager()
|
|
5
|
+
private var continuation: AsyncThrowingStream<CLLocation?, Error>.Continuation?
|
|
6
|
+
|
|
7
|
+
func updates(for profile: Profile, allowsBackgroundUpdates: Bool = false) -> PositionUpdatesSource {
|
|
8
|
+
let (stream, continuation) = AsyncThrowingStream.makeStream(of: CLLocation?.self)
|
|
9
|
+
self.continuation = continuation
|
|
10
|
+
DispatchQueue.main.async {
|
|
11
|
+
self.manager.delegate = self
|
|
12
|
+
self.manager.activityType = profile.clActivityType()
|
|
13
|
+
self.manager.distanceFilter = profile.clDistanceFilter()
|
|
14
|
+
self.manager.desiredAccuracy = profile.clDesiredAccuracy()
|
|
15
|
+
self.manager.allowsBackgroundLocationUpdates = allowsBackgroundUpdates
|
|
16
|
+
self.manager.startUpdatingLocation()
|
|
17
|
+
}
|
|
18
|
+
return PositionUpdatesSource(stream: stream, continuation: continuation) {
|
|
19
|
+
DispatchQueue.main.async {
|
|
20
|
+
self.manager.stopUpdatingLocation()
|
|
21
|
+
self.manager.delegate = nil
|
|
22
|
+
self.continuation = nil
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
|
28
|
+
for location in locations {
|
|
29
|
+
continuation?.yield(location)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
|
34
|
+
switch error {
|
|
35
|
+
case CLError.locationUnknown:
|
|
36
|
+
return
|
|
37
|
+
case CLError.denied:
|
|
38
|
+
continuation?.finish(throwing: LocationAuthorizationDenied())
|
|
39
|
+
default:
|
|
40
|
+
continuation?.finish(throwing: error)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|