react-native-bg-geolocation 0.2.0
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/BgGeolocation.podspec +39 -0
- package/LICENSE +20 -0
- package/README.md +366 -0
- package/android/build.gradle +69 -0
- package/android/src/main/AndroidManifest.xml +53 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationActivityRecognitionReceiver.kt +116 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationBootReceiver.kt +44 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationForegroundService.kt +373 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationGeofenceReceiver.kt +55 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationHeadlessTask.kt +138 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationModule.kt +1030 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationMotionStateMachine.kt +159 -0
- package/android/src/main/java/com/bggeolocation/BgGeolocationPackage.kt +31 -0
- package/android/src/main/res/drawable/bg_geo_notification.xml +9 -0
- package/ios/BgGeolocation.h +14 -0
- package/ios/BgGeolocation.mm +709 -0
- package/ios/engine/AtomicBoolean.swift +48 -0
- package/ios/engine/BGActivityChangeEvent.swift +20 -0
- package/ios/engine/BGActivityConfig.swift +71 -0
- package/ios/engine/BGAppConfig.swift +92 -0
- package/ios/engine/BGAppState.swift +147 -0
- package/ios/engine/BGAuthorization.swift +85 -0
- package/ios/engine/BGAuthorizationAlertPresenter.swift +39 -0
- package/ios/engine/BGAuthorizationConfig.swift +50 -0
- package/ios/engine/BGAuthorizationEvent.swift +40 -0
- package/ios/engine/BGBackgroundTaskManager.swift +143 -0
- package/ios/engine/BGCLRouter.swift +101 -0
- package/ios/engine/BGCallback.swift +19 -0
- package/ios/engine/BGConfig.swift +440 -0
- package/ios/engine/BGConfigModuleBase.swift +180 -0
- package/ios/engine/BGConfigOLD.swift +582 -0
- package/ios/engine/BGConnectivityChangeEvent.swift +15 -0
- package/ios/engine/BGCrashDetector.swift +122 -0
- package/ios/engine/BGCurrentPositionRequest.swift +87 -0
- package/ios/engine/BGDataStore.swift +75 -0
- package/ios/engine/BGDatabase.swift +677 -0
- package/ios/engine/BGDatabasePool.swift +220 -0
- package/ios/engine/BGDatabaseQueue.swift +215 -0
- package/ios/engine/BGDateUtils.swift +26 -0
- package/ios/engine/BGDeviceInfo.swift +54 -0
- package/ios/engine/BGDeviceManager.swift +65 -0
- package/ios/engine/BGEnabledChangeEvent.swift +11 -0
- package/ios/engine/BGEnv.swift +17 -0
- package/ios/engine/BGEventBus.swift +83 -0
- package/ios/engine/BGEventManager.swift +169 -0
- package/ios/engine/BGEventNames.swift +51 -0
- package/ios/engine/BGGeofence.swift +233 -0
- package/ios/engine/BGGeofenceDAO.swift +152 -0
- package/ios/engine/BGGeofenceEvent.swift +42 -0
- package/ios/engine/BGGeofenceLocationRequest.swift +94 -0
- package/ios/engine/BGGeofenceManager.swift +315 -0
- package/ios/engine/BGGeofenceTransition.swift +97 -0
- package/ios/engine/BGGeofencesChangeEvent.swift +26 -0
- package/ios/engine/BGGeolocationConfig.swift +136 -0
- package/ios/engine/BGHeartbeatEvent.swift +31 -0
- package/ios/engine/BGHeartbeatService.swift +51 -0
- package/ios/engine/BGHttpConfig.swift +105 -0
- package/ios/engine/BGHttpErrorCodes.swift +63 -0
- package/ios/engine/BGHttpEvent.swift +34 -0
- package/ios/engine/BGHttpRequest.swift +126 -0
- package/ios/engine/BGHttpResponse.swift +93 -0
- package/ios/engine/BGHttpService.swift +428 -0
- package/ios/engine/BGKalmanFilter.swift +105 -0
- package/ios/engine/BGLMActionNames.swift +55 -0
- package/ios/engine/BGLicenseManager.swift +26 -0
- package/ios/engine/BGLiveActivityManager.swift +327 -0
- package/ios/engine/BGLocation.swift +311 -0
- package/ios/engine/BGLocationAuthorization.swift +427 -0
- package/ios/engine/BGLocationDAO.swift +252 -0
- package/ios/engine/BGLocationErrors.swift +28 -0
- package/ios/engine/BGLocationEvent.swift +43 -0
- package/ios/engine/BGLocationFilter.swift +82 -0
- package/ios/engine/BGLocationFilterConfig.swift +57 -0
- package/ios/engine/BGLocationHelper.swift +54 -0
- package/ios/engine/BGLocationManager.swift +662 -0
- package/ios/engine/BGLocationMetricsEngine.swift +116 -0
- package/ios/engine/BGLocationRequestService.swift +459 -0
- package/ios/engine/BGLocationSatisfier.swift +14 -0
- package/ios/engine/BGLocationStreamEvent.swift +27 -0
- package/ios/engine/BGLog.swift +337 -0
- package/ios/engine/BGLogLevel.swift +26 -0
- package/ios/engine/BGLoggerConfig.swift +60 -0
- package/ios/engine/BGMotionActivity.swift +31 -0
- package/ios/engine/BGMotionActivityClassifier.swift +108 -0
- package/ios/engine/BGMotionActivityManagerAdapter.swift +40 -0
- package/ios/engine/BGMotionActivitySource.swift +46 -0
- package/ios/engine/BGMotionDetector.swift +377 -0
- package/ios/engine/BGMotionPermissionManager.swift +50 -0
- package/ios/engine/BGNativeLogger.swift +48 -0
- package/ios/engine/BGNotificaitons.swift +37 -0
- package/ios/engine/BGOdometer.swift +66 -0
- package/ios/engine/BGPersistenceConfig.swift +29 -0
- package/ios/engine/BGPolygonStreamRequest.swift +48 -0
- package/ios/engine/BGPowerSaveChangeEvent.swift +12 -0
- package/ios/engine/BGPropertySpec.swift +29 -0
- package/ios/engine/BGProviderChangeEvent.swift +31 -0
- package/ios/engine/BGQueue.swift +50 -0
- package/ios/engine/BGRPC.swift +194 -0
- package/ios/engine/BGReachability.swift +58 -0
- package/ios/engine/BGResultSet.swift +157 -0
- package/ios/engine/BGSchedule.swift +228 -0
- package/ios/engine/BGScheduleEvent.swift +13 -0
- package/ios/engine/BGScheduler.swift +116 -0
- package/ios/engine/BGSingleLocationRequest.swift +49 -0
- package/ios/engine/BGStreamLocationRequest.swift +42 -0
- package/ios/engine/BGTemplate.swift +54 -0
- package/ios/engine/BGTimerService.swift +46 -0
- package/ios/engine/BGTrackingAudioManager.swift +286 -0
- package/ios/engine/BGTrackingService.swift +879 -0
- package/ios/engine/BGWatchPositionRequest.swift +63 -0
- package/ios/engine/DatabaseQueue.swift +47 -0
- package/ios/engine/LogQuery.swift +10 -0
- package/ios/engine/SQLQuery.swift +65 -0
- package/ios/engine/TransistorAuthorizationToken.swift +182 -0
- package/ios/liveactivity/BGLiveTrackingAttributes.swift +52 -0
- package/ios/locationpush/BGLocationPushDeliverer.swift +260 -0
- package/ios/locationpush/BGLocationPushService.swift +161 -0
- package/ios/locationpush/BGLocationPushShared.swift +98 -0
- package/ios/locationpush/BGLocationPushSocketClient.swift +198 -0
- package/lib/module/NativeBgGeolocation.js +5 -0
- package/lib/module/NativeBgGeolocation.js.map +1 -0
- package/lib/module/events.js +20 -0
- package/lib/module/events.js.map +1 -0
- package/lib/module/index.js +706 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeBgGeolocation.d.ts +57 -0
- package/lib/typescript/src/NativeBgGeolocation.d.ts.map +1 -0
- package/lib/typescript/src/events.d.ts +18 -0
- package/lib/typescript/src/events.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +238 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +229 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +141 -0
- package/src/NativeBgGeolocation.ts +236 -0
- package/src/events.ts +17 -0
- package/src/index.tsx +935 -0
- package/src/types.ts +254 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public let BGLocationErrorDomain = "BGLocationManager"
|
|
4
|
+
|
|
5
|
+
private let BGLocationErrorMessages: [Int: String] = [
|
|
6
|
+
0: "Location unknown",
|
|
7
|
+
100: "Location did not meet desired accuracy.",
|
|
8
|
+
404: "No location available.",
|
|
9
|
+
408: "Timed out.",
|
|
10
|
+
499: "Request was cancelled",
|
|
11
|
+
503: "Service unavailable"
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
public func BGLocationErrorMessage(_ code: Int) -> String {
|
|
15
|
+
return BGLocationErrorMessages[code] ?? "Location error."
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public func BGMakeLocationError(_ code: Int) -> NSError {
|
|
19
|
+
return NSError(domain: BGLocationErrorDomain,
|
|
20
|
+
code: code,
|
|
21
|
+
userInfo: [NSLocalizedDescriptionKey: BGLocationErrorMessage(code)])
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public func BGMakeError(_ domain: String, _ code: Int) -> NSError {
|
|
25
|
+
return NSError(domain: domain,
|
|
26
|
+
code: code,
|
|
27
|
+
userInfo: [NSLocalizedDescriptionKey: BGLocationErrorMessage(code)])
|
|
28
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import CoreLocation
|
|
3
|
+
|
|
4
|
+
@objc public class BGLocationEvent: NSObject {
|
|
5
|
+
|
|
6
|
+
@objc public var location: CLLocation?
|
|
7
|
+
@objc public var data: [String: Any]
|
|
8
|
+
@objc public var event: String
|
|
9
|
+
@objc public var isMoving: Bool
|
|
10
|
+
@objc public var recordedAt: Date
|
|
11
|
+
@objc public var timestamp: Date
|
|
12
|
+
|
|
13
|
+
@objc public class func create(withTSLocation tsLocation: Any) -> BGLocationEvent {
|
|
14
|
+
let event = BGLocationEvent()
|
|
15
|
+
return event
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@objc public init(locationDictionary: [String: Any], location: CLLocation?) {
|
|
19
|
+
self.data = locationDictionary
|
|
20
|
+
self.location = location
|
|
21
|
+
self.event = locationDictionary["event"] as? String ?? ""
|
|
22
|
+
self.isMoving = locationDictionary["is_moving"] as? Bool ?? false
|
|
23
|
+
self.timestamp = Date()
|
|
24
|
+
self.recordedAt = Date()
|
|
25
|
+
super.init()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc public override init() {
|
|
29
|
+
data = [:]
|
|
30
|
+
event = ""
|
|
31
|
+
isMoving = false
|
|
32
|
+
timestamp = Date()
|
|
33
|
+
recordedAt = Date()
|
|
34
|
+
super.init()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@objc public func toDictionary() -> [String: Any] {
|
|
38
|
+
var dict = data
|
|
39
|
+
dict["event"] = event
|
|
40
|
+
dict["is_moving"] = isMoving
|
|
41
|
+
return dict
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import CoreLocation
|
|
3
|
+
|
|
4
|
+
@objc public class BGLocationFilterResult: NSObject {
|
|
5
|
+
|
|
6
|
+
@objc public var decision: Bool = true
|
|
7
|
+
@objc public var reason: String = ""
|
|
8
|
+
@objc public var accuracy: CLLocationAccuracy = 0
|
|
9
|
+
@objc public var speed: CLLocationSpeed = 0
|
|
10
|
+
@objc public var deltaRaw: Double = 0
|
|
11
|
+
@objc public var deltaSmoothed: Double = 0
|
|
12
|
+
@objc public var deltaEffective: Double = 0
|
|
13
|
+
@objc public var distanceFilter: CLLocationDistance = 0
|
|
14
|
+
@objc public var odometerSigma: Double = 0
|
|
15
|
+
@objc public var cap: Double = 0
|
|
16
|
+
|
|
17
|
+
@objc public override var description: String {
|
|
18
|
+
return "<BGLocationFilterResult decision=\(decision) reason=\(reason) delta=\(deltaEffective)>"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc public class BGLocationFilter: NSObject {
|
|
23
|
+
|
|
24
|
+
@objc public var type: String = "NONE"
|
|
25
|
+
@objc public var policy: String = "NONE"
|
|
26
|
+
@objc public var configured: Bool = false
|
|
27
|
+
@objc public var debug: Bool = false
|
|
28
|
+
@objc public var useKalman: Bool = false
|
|
29
|
+
@objc public var kalmanDebug: Bool = false
|
|
30
|
+
@objc public var kalmanProfile: String = "default"
|
|
31
|
+
@objc public var accuracyThreshold: CLLocationAccuracy = 0
|
|
32
|
+
|
|
33
|
+
private var accumulatedAccuracySquaredValue: Double = 0
|
|
34
|
+
private var kalman: BGKalmanFilter?
|
|
35
|
+
|
|
36
|
+
@objc public init(type: String) {
|
|
37
|
+
self.type = type
|
|
38
|
+
super.init()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@objc public override init() {
|
|
42
|
+
super.init()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@objc public func configure(_ config: BGLocationFilterConfig) {
|
|
46
|
+
applyConfig(config)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc public func applyConfig(_ config: BGLocationFilterConfig) {
|
|
50
|
+
policy = config.policy
|
|
51
|
+
debug = config.filterDebug
|
|
52
|
+
useKalman = config.useKalman
|
|
53
|
+
kalmanDebug = config.kalmanDebug
|
|
54
|
+
kalmanProfile = config.kalmanProfile
|
|
55
|
+
accuracyThreshold = config.odometerAccuracyThreshold
|
|
56
|
+
configured = true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc public func evaluateWithMetrics(_ metrics: BGLocationMetrics) -> BGLocationFilterResult {
|
|
60
|
+
let result = BGLocationFilterResult()
|
|
61
|
+
result.decision = true
|
|
62
|
+
result.reason = "PASS"
|
|
63
|
+
return result
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc public func reset() {
|
|
67
|
+
accumulatedAccuracySquaredValue = 0
|
|
68
|
+
kalman = nil
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@objc public func onMotionChange(_ isMoving: Bool) {
|
|
72
|
+
reset()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@objc public func accumulateAccuracy(withMeasurement measurement: Double) {
|
|
76
|
+
accumulatedAccuracySquaredValue += measurement * measurement
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@objc public func seedAccumulatedAccuracySquared(_ value: Double) {
|
|
80
|
+
accumulatedAccuracySquaredValue = value
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
@objc public class BGLocationFilterConfig: BGConfigModuleBase {
|
|
4
|
+
|
|
5
|
+
@objc public var policy: String = "NONE"
|
|
6
|
+
@objc public var burstWindow: Double = 60.0
|
|
7
|
+
@objc public var maxBurstDistance: Double = 100.0
|
|
8
|
+
@objc public var rollingWindow: Int = 10
|
|
9
|
+
@objc public var maxImpliedSpeed: Double = 514.0
|
|
10
|
+
@objc public var odometerAccuracyThreshold: Double = 100.0
|
|
11
|
+
@objc public var odometerUseKalmanFilter: Bool = true
|
|
12
|
+
@objc public var trackingAccuracyThreshold: Double = 0.0
|
|
13
|
+
@objc public var filterDebug: Bool = false
|
|
14
|
+
@objc public var useKalman: Bool = false
|
|
15
|
+
@objc public var kalmanDebug: Bool = false
|
|
16
|
+
@objc public var kalmanProfile: String = "default"
|
|
17
|
+
|
|
18
|
+
@objc public override func applyDefaults() {
|
|
19
|
+
policy = "NONE"
|
|
20
|
+
burstWindow = 60.0
|
|
21
|
+
maxBurstDistance = 100.0
|
|
22
|
+
rollingWindow = 10
|
|
23
|
+
maxImpliedSpeed = 514.0
|
|
24
|
+
odometerAccuracyThreshold = 100.0
|
|
25
|
+
odometerUseKalmanFilter = true
|
|
26
|
+
trackingAccuracyThreshold = 0.0
|
|
27
|
+
filterDebug = false
|
|
28
|
+
useKalman = false
|
|
29
|
+
kalmanDebug = false
|
|
30
|
+
kalmanProfile = "default"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@objc public func moduleKey() -> String {
|
|
34
|
+
return "filter"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@objc public override func deprecatedPropertyMappings() -> [String: String] {
|
|
38
|
+
return [:]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@objc public override func propertySpecs() -> [BGPropertySpecImpl] {
|
|
42
|
+
return [
|
|
43
|
+
BGPropertySpec(name: "policy", type: "string"),
|
|
44
|
+
BGPropertySpec(name: "burstWindow", type: "double"),
|
|
45
|
+
BGPropertySpec(name: "maxBurstDistance", type: "double"),
|
|
46
|
+
BGPropertySpec(name: "rollingWindow", type: "int"),
|
|
47
|
+
BGPropertySpec(name: "maxImpliedSpeed", type: "double"),
|
|
48
|
+
BGPropertySpec(name: "odometerAccuracyThreshold", type: "double"),
|
|
49
|
+
BGPropertySpec(name: "odometerUseKalmanFilter", type: "bool"),
|
|
50
|
+
BGPropertySpec(name: "trackingAccuracyThreshold", type: "double"),
|
|
51
|
+
BGPropertySpec(name: "filterDebug", type: "bool"),
|
|
52
|
+
BGPropertySpec(name: "useKalman", type: "bool"),
|
|
53
|
+
BGPropertySpec(name: "kalmanDebug", type: "bool"),
|
|
54
|
+
BGPropertySpec(name: "kalmanProfile", type: "string")
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import CoreLocation
|
|
3
|
+
|
|
4
|
+
@objc public class BGLocationHelper: NSObject {
|
|
5
|
+
|
|
6
|
+
@objc public class func isAccurate(
|
|
7
|
+
_ location: CLLocation,
|
|
8
|
+
desiredAccuracy: CLLocationAccuracy
|
|
9
|
+
) -> Bool {
|
|
10
|
+
guard location.horizontalAccuracy >= 0 else { return false }
|
|
11
|
+
if desiredAccuracy == kCLLocationAccuracyBest ||
|
|
12
|
+
desiredAccuracy == kCLLocationAccuracyBestForNavigation {
|
|
13
|
+
return location.horizontalAccuracy < 100
|
|
14
|
+
}
|
|
15
|
+
return location.horizontalAccuracy <= desiredAccuracy
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@objc public class func locationAge(_ location: CLLocation) -> TimeInterval {
|
|
19
|
+
return Date().timeIntervalSince(location.timestamp)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc public class func sameTimestamp(_ a: CLLocation, as b: CLLocation) -> Bool {
|
|
23
|
+
return abs(a.timestamp.timeIntervalSince(b.timestamp)) < 0.001
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@objc public class func pickBestLocation(
|
|
27
|
+
between a: CLLocation?,
|
|
28
|
+
and b: CLLocation?,
|
|
29
|
+
desiredAccuracy: CLLocationAccuracy
|
|
30
|
+
) -> CLLocation? {
|
|
31
|
+
guard let a = a else { return b }
|
|
32
|
+
guard let b = b else { return a }
|
|
33
|
+
if a.horizontalAccuracy < 0 { return b }
|
|
34
|
+
if b.horizontalAccuracy < 0 { return a }
|
|
35
|
+
return a.horizontalAccuracy <= b.horizontalAccuracy ? a : b
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@objc public class func resolveLocation(
|
|
39
|
+
withNow now: Date,
|
|
40
|
+
desiredAccuracy: CLLocationAccuracy,
|
|
41
|
+
allowStale: Bool,
|
|
42
|
+
maximumAgeSeconds: Double,
|
|
43
|
+
bestLocation: CLLocation?,
|
|
44
|
+
mostAccurateLocation: CLLocation?,
|
|
45
|
+
freshestLocation: CLLocation?
|
|
46
|
+
) -> CLLocation? {
|
|
47
|
+
let candidates = [bestLocation, mostAccurateLocation, freshestLocation].compactMap { $0 }
|
|
48
|
+
let fresh = candidates.filter { now.timeIntervalSince($0.timestamp) <= maximumAgeSeconds }
|
|
49
|
+
if allowStale || fresh.isEmpty {
|
|
50
|
+
return candidates.min(by: { $0.horizontalAccuracy < $1.horizontalAccuracy })
|
|
51
|
+
}
|
|
52
|
+
return fresh.min(by: { $0.horizontalAccuracy < $1.horizontalAccuracy })
|
|
53
|
+
}
|
|
54
|
+
}
|