expo-location 58.0.12 → 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 +11 -0
- package/android/build.gradle +2 -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.12/expo.modules.location-58.0.12.module → 58.0.13/expo.modules.location-58.0.13.module} +7 -7
- 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.12/expo.modules.location-58.0.12.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 +32 -3
- 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.12/expo.modules.location-58.0.12.module.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.sha512 +0 -1
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-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.12/expo.modules.location-58.0.12-sources.jar.md5 → 58.0.13/expo.modules.location-58.0.13-sources.jar.md5} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.sha1 → 58.0.13/expo.modules.location-58.0.13-sources.jar.sha1} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.sha256 → 58.0.13/expo.modules.location-58.0.13-sources.jar.sha256} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.sha512 → 58.0.13/expo.modules.location-58.0.13-sources.jar.sha512} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar → 58.0.13/expo.modules.location-58.0.13.aar} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.md5 → 58.0.13/expo.modules.location-58.0.13.aar.md5} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.sha1 → 58.0.13/expo.modules.location-58.0.13.aar.sha1} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.sha256 → 58.0.13/expo.modules.location-58.0.13.aar.sha256} +0 -0
- /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.sha512 → 58.0.13/expo.modules.location-58.0.13.aar.sha512} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare enum LocationProfile {
|
|
2
|
+
DEFAULT = "default",
|
|
3
|
+
AUTOMOTIVE_NAVIGATION = "automotiveNavigation",
|
|
4
|
+
OTHER_NAVIGATION = "otherNavigation",
|
|
5
|
+
FITNESS = "fitness",
|
|
6
|
+
AIRBORNE = "airborne",
|
|
7
|
+
LOW_POWER = "lowPower"
|
|
8
|
+
}
|
|
9
|
+
export type Coordinates = {
|
|
10
|
+
latitude: number;
|
|
11
|
+
longitude: number;
|
|
12
|
+
};
|
|
13
|
+
export type Position = {
|
|
14
|
+
coordinates: Coordinates;
|
|
15
|
+
horizontalAccuracy: number | null;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
altitude: number | null;
|
|
18
|
+
mslAltitude: number | null;
|
|
19
|
+
verticalAccuracy: number | null;
|
|
20
|
+
mocked: boolean;
|
|
21
|
+
heading: number | null;
|
|
22
|
+
headingAccuracy: number | null;
|
|
23
|
+
speed: number | null;
|
|
24
|
+
speedAccuracy: number | null;
|
|
25
|
+
};
|
|
26
|
+
export type GetPositionOptions = {
|
|
27
|
+
maxCachedAge?: number;
|
|
28
|
+
timeout?: number;
|
|
29
|
+
profile?: LocationProfile;
|
|
30
|
+
};
|
|
31
|
+
export type PositionWatchError = {
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
export type PositionUpdate = {
|
|
36
|
+
data: Position;
|
|
37
|
+
error: null;
|
|
38
|
+
} | {
|
|
39
|
+
data: null;
|
|
40
|
+
error: PositionWatchError;
|
|
41
|
+
};
|
|
42
|
+
export type PositionWatchStatus = {
|
|
43
|
+
/** Whether the provider is feeding positions right now. */
|
|
44
|
+
isSubscribed: boolean;
|
|
45
|
+
/** Whether the handle can still be brought back to sending. False only once released. */
|
|
46
|
+
isHandleAlive: boolean;
|
|
47
|
+
isStarted: boolean;
|
|
48
|
+
isPaused: boolean;
|
|
49
|
+
isInForeground: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type WatchPositionParams = {
|
|
52
|
+
profile?: LocationProfile;
|
|
53
|
+
onPosition: (position: Position) => void;
|
|
54
|
+
onError?: (error: PositionWatchError) => void;
|
|
55
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export var LocationProfile = /*#__PURE__*/ function(LocationProfile) {
|
|
2
|
+
LocationProfile["DEFAULT"] = "default";
|
|
3
|
+
LocationProfile["AUTOMOTIVE_NAVIGATION"] = "automotiveNavigation";
|
|
4
|
+
LocationProfile["OTHER_NAVIGATION"] = "otherNavigation";
|
|
5
|
+
LocationProfile["FITNESS"] = "fitness";
|
|
6
|
+
LocationProfile["AIRBORNE"] = "airborne";
|
|
7
|
+
LocationProfile["LOW_POWER"] = "lowPower";
|
|
8
|
+
return LocationProfile;
|
|
9
|
+
}({});
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=Position.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["next/types/Position.types.ts"],"sourcesContent":[null],"names":["LocationProfile"],"mappings":"AAAA,OAAO,IAAA,AAAKA,yCAAAA;;;;;;;WAAAA;MAOX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["next/types/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,sBAAsB;AACpC,cAAc,2BAA2B"}
|
package/expo-module.config.json
CHANGED
package/ios/EXLocation.m
CHANGED
package/ios/ExpoLocation.podspec
CHANGED
|
@@ -29,4 +29,13 @@ Pod::Spec.new do |s|
|
|
|
29
29
|
s.pod_target_xcconfig = pod_target_xcconfig
|
|
30
30
|
|
|
31
31
|
s.source_files = "**/*.{h,m,swift}"
|
|
32
|
+
s.exclude_files = 'Tests/'
|
|
33
|
+
|
|
34
|
+
s.test_spec 'Tests' do |test_spec|
|
|
35
|
+
test_spec.dependency 'ExpoModulesTestCore'
|
|
36
|
+
test_spec.source_files = 'Tests/**/*.{m,swift}'
|
|
37
|
+
test_spec.pod_target_xcconfig = {
|
|
38
|
+
'OTHER_LDFLAGS' => '$(inherited) -lc++',
|
|
39
|
+
}
|
|
40
|
+
end
|
|
32
41
|
end
|
package/ios/LocationUtils.swift
CHANGED
|
@@ -30,7 +30,9 @@ internal func exportLocation(_ location: CLLocation) -> [String: Any] {
|
|
|
30
30
|
"heading": location.course,
|
|
31
31
|
"speed": location.speed
|
|
32
32
|
],
|
|
33
|
-
"timestamp": location.timestamp.timeIntervalSince1970 * 1000
|
|
33
|
+
"timestamp": location.timestamp.timeIntervalSince1970 * 1000,
|
|
34
|
+
// `sourceInformation` is nil for ordinary fixes; it is set for simulated or accessory-produced ones.
|
|
35
|
+
"mocked": location.sourceInformation?.isSimulatedBySoftware ?? false
|
|
34
36
|
]
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
public final class LocationModuleNext: Module {
|
|
5
|
+
private lazy var permissions = LocationPermissionsDelegate(appContext: appContext)
|
|
6
|
+
private lazy var accessGuard = LocationAccessGuard(appContext: appContext)
|
|
7
|
+
|
|
8
|
+
public func definition() -> ModuleDefinition {
|
|
9
|
+
Name("LocationModuleNext")
|
|
10
|
+
|
|
11
|
+
OnCreate {
|
|
12
|
+
permissions.registerRequesters()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
AsyncFunction("getForegroundPermissions") { (promise: Promise) in
|
|
16
|
+
try permissions.getForegroundPermissions(promise)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
AsyncFunction("requestForegroundPermissions") { (options: PermissionsRequestOptions?, promise: Promise) in
|
|
20
|
+
try permissions.requestForegroundPermissions(options: options ?? PermissionsRequestOptions(), promise)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
AsyncFunction("getBackgroundPermissions") { (promise: Promise) in
|
|
24
|
+
try permissions.getBackgroundPermissions(promise)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
AsyncFunction("requestBackgroundPermissions") { (options: PermissionsRequestOptions?, promise: Promise) in
|
|
28
|
+
try permissions.requestBackgroundPermissions(options: options ?? PermissionsRequestOptions(), promise)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
AsyncFunction("getPosition") { (options: GetPositionOptions?) -> Position? in
|
|
32
|
+
guard CLLocationManager.locationServicesEnabled() else {
|
|
33
|
+
throw LocationServicesDisabledGlobally()
|
|
34
|
+
}
|
|
35
|
+
try accessGuard.checkPermissions(.foreground)
|
|
36
|
+
|
|
37
|
+
let location = try await PositionRequester().get(options: options ?? GetPositionOptions())
|
|
38
|
+
return location?.toPosition()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Function("watchPosition") { (profile: Profile?) -> PositionWatcher in
|
|
42
|
+
guard CLLocationManager.locationServicesEnabled() else {
|
|
43
|
+
throw LocationServicesDisabledGlobally()
|
|
44
|
+
}
|
|
45
|
+
try accessGuard.checkPermissions(.foreground)
|
|
46
|
+
|
|
47
|
+
let watcher = PositionWatcher(profile: profile ?? .default)
|
|
48
|
+
watcher.start()
|
|
49
|
+
return watcher
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Class("PositionWatchHandle", PositionWatcher.self) {
|
|
53
|
+
Function("pause") { (watcher: PositionWatcher) in
|
|
54
|
+
watcher.pause()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Function("resume") { (watcher: PositionWatcher) -> Bool in
|
|
58
|
+
watcher.resume()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Function("withProfile") { (watcher: PositionWatcher, profile: Profile) -> PositionWatcher in
|
|
62
|
+
watcher.withProfile(profile)
|
|
63
|
+
return watcher
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Function("withInterval") { (watcher: PositionWatcher, intervalSeconds: Double) throws -> PositionWatcher in
|
|
67
|
+
try watcher.withInterval(intervalSeconds)
|
|
68
|
+
return watcher
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Function("restart") { (watcher: PositionWatcher) -> Bool in
|
|
72
|
+
watcher.restart()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Function("status") { (watcher: PositionWatcher) -> PositionWatchStatus in
|
|
76
|
+
watcher.status()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
OnAppEntersForeground {
|
|
81
|
+
PositionWatcher.isAppInForeground = true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
OnAppEntersBackground {
|
|
85
|
+
PositionWatcher.isAppInForeground = false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Class(LocationUpdatesHandle.self) {
|
|
89
|
+
Constructor { (taskName: String) -> LocationUpdatesHandle in
|
|
90
|
+
LocationUpdatesHandle(taskName: taskName, accessGuard: accessGuard)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Function("withProfile") { (handle: LocationUpdatesHandle, profile: Profile) in
|
|
94
|
+
handle.withProfile(profile)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
AsyncFunction("start") { (handle: LocationUpdatesHandle) in
|
|
98
|
+
try handle.start()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
AsyncFunction("stop") { (handle: LocationUpdatesHandle) in
|
|
102
|
+
try handle.stop()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
AsyncFunction("hasStarted") { (handle: LocationUpdatesHandle) -> Bool in
|
|
106
|
+
try handle.hasStarted()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
final class InvalidLocationTimeoutException: Exception, @unchecked Sendable {
|
|
4
|
+
override var reason: String {
|
|
5
|
+
"Location timeout must be a non-negative number of seconds or positive Infinity"
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
final class InvalidMaxCachedAgeException: Exception, @unchecked Sendable {
|
|
10
|
+
override var reason: String {
|
|
11
|
+
"maxCachedAge must be a non-negative number of seconds"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
final class InvalidWatchIntervalException: Exception, @unchecked Sendable {
|
|
16
|
+
override var reason: String {
|
|
17
|
+
"Location update interval must be a finite, non-negative number of seconds"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
final class LocationAuthorizationDenied: Exception, @unchecked Sendable {
|
|
22
|
+
override var reason: String {
|
|
23
|
+
"Location access for this app has been turned off, so the updates stopped. The user changed it " +
|
|
24
|
+
"in Settings while the app was running, and requesting the permission again will not prompt " +
|
|
25
|
+
"them - iOS only asks once. Ask the user to allow location for this app in Settings, then start " +
|
|
26
|
+
"watching again"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
final class LocationAuthorizationRestricted: Exception, @unchecked Sendable {
|
|
31
|
+
override var reason: String {
|
|
32
|
+
"Location access is restricted on this device, so the app cannot receive location updates. " +
|
|
33
|
+
"Authorization changes are prevented by parental restrictions, an MDM configuration, or another " +
|
|
34
|
+
"device policy, not by the user's choice, so requesting the permission again will not help. Ask " +
|
|
35
|
+
"the user to check Screen Time content and privacy restrictions, or contact whoever manages the device"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
final class LocationServiceSessionRequired: Exception, @unchecked Sendable {
|
|
40
|
+
override var reason: String {
|
|
41
|
+
"Location updates stopped because this app sets 'CLRequireExplicitServiceSession' in its " +
|
|
42
|
+
"Info.plist, which makes the system refuse updates unless the app holds a CLServiceSession. " +
|
|
43
|
+
"'expo-location' does not create one. Remove that key from your Info.plist, or manage the session " +
|
|
44
|
+
"yourself and use CoreLocation directly"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
final class LocationUpdatesEndedUnexpectedly: Exception, @unchecked Sendable {
|
|
49
|
+
override var reason: String {
|
|
50
|
+
"The system stopped delivering location updates without reporting a reason, and the app did not " +
|
|
51
|
+
"stop them. Start the updates again; if this repeats, check that location permissions are still " +
|
|
52
|
+
"granted and that Location Services are enabled"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
final class LocationServicesDisabledGlobally: Exception, @unchecked Sendable {
|
|
57
|
+
override var reason: String {
|
|
58
|
+
"Location Services are turned off for the whole device, so no app can receive location updates. " +
|
|
59
|
+
"This is a system-wide setting the app cannot change or prompt for. Ask the user to enable it in " +
|
|
60
|
+
"Settings > Privacy & Security > Location Services"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
final class MissingPermissionsException: GenericException<LocationPermissionKind>, @unchecked Sendable {
|
|
65
|
+
override var reason: String {
|
|
66
|
+
"\(param.permissionName) permission is required to do this operation. " +
|
|
67
|
+
"Request it with \(param.requestFunctionName)() before calling this method"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
final class PermissionsModuleUnavailable: Exception, @unchecked Sendable {
|
|
72
|
+
override var reason: String {
|
|
73
|
+
"Cannot check location permissions because the app context or its permissions service is no " +
|
|
74
|
+
"longer available. This happens when the module outlives its app context, for example while " +
|
|
75
|
+
"the app is reloading, or when the permissions service was not registered on that context. " +
|
|
76
|
+
"Reload the app and try again; if the error persists, report it at " +
|
|
77
|
+
"https://github.com/expo/expo/issues"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
final class TaskManagerUnavailable: Exception, @unchecked Sendable {
|
|
82
|
+
override var reason: String {
|
|
83
|
+
"'expo-task-manager' module is required to use background services"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
final class SignificantLocationChangesUnavailable: Exception, @unchecked Sendable {
|
|
88
|
+
override var reason: String {
|
|
89
|
+
"This device cannot monitor significant location changes, which background location updates " +
|
|
90
|
+
"are built on. The capability is missing on this hardware, and the app cannot turn it on. " +
|
|
91
|
+
"Watch the position while the app runs instead of registering a background task"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
final class MissingLocationBackgroundMode: Exception, @unchecked Sendable {
|
|
96
|
+
override var reason: String {
|
|
97
|
+
"Background location updates need 'location' in the 'UIBackgroundModes' array of your " +
|
|
98
|
+
"Info.plist, and this app does not declare it, so the system would stop the updates as soon " +
|
|
99
|
+
"as the app leaves the foreground. Set 'isIosBackgroundLocationEnabled' in the 'expo-location' " +
|
|
100
|
+
"config plugin, or add the key by hand, then rebuild the app"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
final class PermissionRequestFailedException: Exception, @unchecked Sendable {
|
|
105
|
+
override var reason: String {
|
|
106
|
+
"The system reported an error while requesting location permissions, so the request could not " +
|
|
107
|
+
"finish. This is rare and usually transient. Ask again; if it repeats, the attached error " +
|
|
108
|
+
"describes what CoreLocation refused"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
final class MissingPlistKeyException: GenericException<String>, @unchecked Sendable {
|
|
113
|
+
override var reason: String {
|
|
114
|
+
"Cannot access the location because '\(param)' is missing from your Info.plist. iOS refuses " +
|
|
115
|
+
"location access to an app that does not declare why it needs it, so the permission can never be " +
|
|
116
|
+
"granted. Add the key via the expo-location config plugin or by hand, then rebuild the app"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
final class LocationUpdatesHandle: SharedObject {
|
|
5
|
+
var taskName: String
|
|
6
|
+
private var profile: Profile = .default
|
|
7
|
+
private let accessGuard: LocationAccessGuard
|
|
8
|
+
|
|
9
|
+
init(taskName: String, accessGuard: LocationAccessGuard) {
|
|
10
|
+
self.taskName = taskName
|
|
11
|
+
self.accessGuard = accessGuard
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func withProfile(_ profile: Profile) {
|
|
15
|
+
self.profile = profile
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func start() throws {
|
|
19
|
+
guard CLLocationManager.locationServicesEnabled() else {
|
|
20
|
+
throw LocationServicesDisabledGlobally()
|
|
21
|
+
}
|
|
22
|
+
try accessGuard.checkPermissions(.foreground)
|
|
23
|
+
guard CLLocationManager.significantLocationChangeMonitoringAvailable() else {
|
|
24
|
+
throw SignificantLocationChangesUnavailable()
|
|
25
|
+
}
|
|
26
|
+
let taskManager = try taskManager()
|
|
27
|
+
guard taskManager.hasBackgroundModeEnabled("location") else {
|
|
28
|
+
throw MissingLocationBackgroundMode()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
taskManager.registerTask(
|
|
32
|
+
withName: taskName,
|
|
33
|
+
consumer: LocationUpdatesTaskConsumer.self,
|
|
34
|
+
options: LocationUpdatesTaskOptions(profile: profile).toDictionary()
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func stop() throws {
|
|
39
|
+
try taskManager().unregisterTask(withName: taskName, consumerClass: LocationUpdatesTaskConsumer.self)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func hasStarted() throws -> Bool {
|
|
43
|
+
return try taskManager().hasRegisteredTask(withName: taskName)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private func taskManager() throws -> EXTaskManagerInterface {
|
|
47
|
+
guard let taskManager: EXTaskManagerInterface = appContext?.legacyModule(implementing: EXTaskManagerInterface.self) else {
|
|
48
|
+
throw TaskManagerUnavailable()
|
|
49
|
+
}
|
|
50
|
+
return taskManager
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import CoreLocation
|
|
3
|
+
|
|
4
|
+
final class LocationUpdatesTaskConsumer: NSObject, EXTaskConsumerInterface {
|
|
5
|
+
var task: (any EXTaskInterface)?
|
|
6
|
+
var makeSource: (_ profile: Profile) -> PositionUpdatesSource = PositionUpdatesSource.background
|
|
7
|
+
private(set) var subscription: PositionUpdatesSubscription?
|
|
8
|
+
private let relaunchMonitor = SignificantLocationChangeMonitor()
|
|
9
|
+
|
|
10
|
+
func didRegisterTask(_ task: any EXTaskInterface) {
|
|
11
|
+
let options = LocationUpdatesTaskOptions(task.options)
|
|
12
|
+
subscription?.stop()
|
|
13
|
+
subscription = PositionUpdatesSubscription(
|
|
14
|
+
source: makeSource(options.profile),
|
|
15
|
+
onLocation: { location in
|
|
16
|
+
task.execute(withData: location.toPosition().toEventPayload(), withError: nil)
|
|
17
|
+
},
|
|
18
|
+
onError: { error in
|
|
19
|
+
task.execute(withData: nil, withError: error)
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// liveUpdates relaunches a terminated app on its own; the CLLocationManager path needs
|
|
24
|
+
// significant-change monitoring to be relaunched. It can be removed once we drop support for iOS 17
|
|
25
|
+
if #available(iOS 17.0, *), options.profile != .lowPower {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
relaunchMonitor.start()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func taskType() -> String {
|
|
32
|
+
return "locationNext"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func didUnregister() {
|
|
36
|
+
relaunchMonitor.stop()
|
|
37
|
+
subscription?.stop()
|
|
38
|
+
subscription = nil
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
struct LocationUpdatesTaskOptions {
|
|
2
|
+
let profile: Profile
|
|
3
|
+
|
|
4
|
+
init(profile: Profile) {
|
|
5
|
+
self.profile = profile
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
init(_ dictionary: [AnyHashable: Any]?) {
|
|
9
|
+
if let rawProfile = dictionary?["profile"] as? String, let profile = Profile(rawValue: rawProfile) {
|
|
10
|
+
self.profile = profile
|
|
11
|
+
} else {
|
|
12
|
+
profile = .default
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func toDictionary() -> [String: Any] {
|
|
17
|
+
return ["profile": profile.rawValue]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
|
|
3
|
+
final class SignificantLocationChangeMonitor {
|
|
4
|
+
private var manager: CLLocationManager?
|
|
5
|
+
|
|
6
|
+
func start() {
|
|
7
|
+
DispatchQueue.main.async {
|
|
8
|
+
let manager = self.manager ?? CLLocationManager()
|
|
9
|
+
self.manager = manager
|
|
10
|
+
manager.startMonitoringSignificantLocationChanges()
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func stop() {
|
|
15
|
+
DispatchQueue.main.async {
|
|
16
|
+
self.manager?.stopMonitoringSignificantLocationChanges()
|
|
17
|
+
self.manager = nil
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
final class BackgroundPermissionsRequester: LocationPermissionsRequester {
|
|
5
|
+
private var wasAsked = false
|
|
6
|
+
|
|
7
|
+
private lazy var alwaysAuthorizationRequest = LocationManagerAlwaysAuthorizationRequest(locationManager: locationManager)
|
|
8
|
+
|
|
9
|
+
init() {
|
|
10
|
+
super.init(kind: .background)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override class func permissionType() -> String {
|
|
14
|
+
return "locationBackgroundNext"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@MainActor
|
|
18
|
+
override func requestFromSystem() async {
|
|
19
|
+
do {
|
|
20
|
+
try await alwaysAuthorizationRequest.request()
|
|
21
|
+
wasAsked = true
|
|
22
|
+
resolvePendingRequests()
|
|
23
|
+
} catch {
|
|
24
|
+
rejectPendingRequests(with: error)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override func whenInUseResponse(accuracy: CLAccuracyAuthorization) -> LocationPermissionResponse {
|
|
29
|
+
return LocationPermissionResponse.whenInUse(
|
|
30
|
+
status: wasAsked ? EXPermissionStatusDenied : EXPermissionStatusUndetermined,
|
|
31
|
+
accuracy: accuracy
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import ExpoModulesCore
|
|
3
|
+
|
|
4
|
+
final class ForegroundPermissionsRequester: LocationPermissionsRequester, CLLocationManagerDelegate {
|
|
5
|
+
// The selector is constructed at runtime from separate parts so that neither the selector
|
|
6
|
+
// nor the full method name literal ends up in the binary. Apple's static analysis warns
|
|
7
|
+
// developers when it sees this method called while the matching usage description may be
|
|
8
|
+
// missing from Info.plist - we let the provided NSLocation*UsageDescription keys govern
|
|
9
|
+
// the behavior instead.
|
|
10
|
+
private static let whenInUseAuthorizationSelector = NSSelectorFromString(["request", "WhenInUseAuthorization"].joined())
|
|
11
|
+
|
|
12
|
+
init() {
|
|
13
|
+
super.init(kind: .foreground)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override class func permissionType() -> String {
|
|
17
|
+
return "locationForegroundNext"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@MainActor
|
|
21
|
+
override func requestFromSystem() async {
|
|
22
|
+
locationManager.delegate = self
|
|
23
|
+
locationManager.perform(Self.whenInUseAuthorizationSelector)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
|
|
27
|
+
rejectPendingRequests(with: error)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
|
31
|
+
// notDetermined authorizationStatus means that user has not clicked the pop-up yet
|
|
32
|
+
// this check is important because this callback runs on the manager initalization with notDetermined
|
|
33
|
+
guard manager.authorizationStatus != .notDetermined else {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
resolvePendingRequests()
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
final class LocationAccessGuard {
|
|
4
|
+
private weak var appContext: AppContext?
|
|
5
|
+
|
|
6
|
+
init(appContext: AppContext?) {
|
|
7
|
+
self.appContext = appContext
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
func checkPermissions(_ kind: LocationPermissionKind) throws {
|
|
11
|
+
if let missingKey = LocationPlistKeys.firstMissing(in: kind.plistKeys) {
|
|
12
|
+
throw MissingPlistKeyException(missingKey)
|
|
13
|
+
}
|
|
14
|
+
guard let permissionsManager = appContext?.permissions else {
|
|
15
|
+
throw PermissionsModuleUnavailable()
|
|
16
|
+
}
|
|
17
|
+
guard permissionsManager.hasGrantedPermission(usingRequesterClass: kind.requesterClass) else {
|
|
18
|
+
throw MissingPermissionsException(kind)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
|
|
3
|
+
enum LocationAccuracyAuthorization: String {
|
|
4
|
+
case full, reduced, notGranted
|
|
5
|
+
|
|
6
|
+
static func from(_ accuracyAuthorization: CLAccuracyAuthorization) -> LocationAccuracyAuthorization {
|
|
7
|
+
return accuracyAuthorization == .reducedAccuracy ? .reduced : .full
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -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
|
+
}
|