@capgo/background-geolocation 7.2.8 → 8.0.2

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.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '14.0'
14
+ s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/Package.swift CHANGED
@@ -3,14 +3,14 @@ import PackageDescription
3
3
 
4
4
  let package = Package(
5
5
  name: "CapgoBackgroundGeolocation",
6
- platforms: [.iOS(.v14)],
6
+ platforms: [.iOS(.v15)],
7
7
  products: [
8
8
  .library(
9
9
  name: "CapgoBackgroundGeolocation",
10
10
  targets: ["CapgoBackgroundGeolocationPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
14
  ],
15
15
  targets: [
16
16
  .target(
@@ -1,10 +1,10 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
6
  androidxLocalbroadcastmanagerVersion = project.hasProperty('androidxLocalbroadcastmanagerVersion') ? rootProject.ext.androidxLocalbroadcastmanagerVersion : '1.0.0'
7
- playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '21.0.1'
7
+ playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '21.3.0'
8
8
  }
9
9
 
10
10
  buildscript {
@@ -13,18 +13,18 @@ buildscript {
13
13
  mavenCentral()
14
14
  }
15
15
  dependencies {
16
- classpath 'com.android.tools.build:gradle:8.7.3'
16
+ classpath 'com.android.tools.build:gradle:8.13.0'
17
17
  }
18
18
  }
19
19
 
20
20
  apply plugin: 'com.android.library'
21
21
 
22
22
  android {
23
- namespace "com.capgo.capacitor_background_geolocation"
24
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
+ namespace = "com.capgo.capacitor_background_geolocation"
24
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
25
25
  defaultConfig {
26
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
27
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
27
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
28
28
  versionCode 1
29
29
  versionName "1.0"
30
30
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -36,7 +36,7 @@ android {
36
36
  }
37
37
  }
38
38
  lintOptions {
39
- abortOnError false
39
+ abortOnError = false
40
40
  }
41
41
  compileOptions {
42
42
  sourceCompatibility JavaVersion.VERSION_21
@@ -1,3 +1,4 @@
1
+ // swiftlint:disable file_length
1
2
  import Capacitor
2
3
  import Foundation
3
4
  import UIKit
@@ -13,8 +14,8 @@ func formatLocation(_ location: CLLocation) -> PluginCallResultData {
13
14
  // Prior to iOS 15, it was not possible to detect simulated locations.
14
15
  // But in general, it is very difficult to simulate locations on iOS in
15
16
  // production.
16
- if location.sourceInformation != nil {
17
- simulated = location.sourceInformation!.isSimulatedBySoftware
17
+ if let sourceInfo = location.sourceInformation {
18
+ simulated = sourceInfo.isSimulatedBySoftware
18
19
  }
19
20
  }
20
21
  return [
@@ -35,8 +36,9 @@ func formatLocation(_ location: CLLocation) -> PluginCallResultData {
35
36
  }
36
37
 
37
38
  @objc(BackgroundGeolocation)
39
+ // swiftlint:disable:next type_body_length
38
40
  public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBridgedPlugin {
39
- private let pluginVersion: String = "7.2.8"
41
+ private let pluginVersion: String = "8.0.2"
40
42
  public let identifier = "BackgroundGeolocationPlugin"
41
43
  public let jsName = "BackgroundGeolocation"
42
44
  public let pluginMethods: [CAPPluginMethod] = [
@@ -57,7 +59,7 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBri
57
59
  private var distanceThreshold: Double = 50.0 // Default distance threshold in meters
58
60
 
59
61
  // Earth radius in meters for distance calculations
60
- private static let EARTH_RADIUS_M: Double = 6371000.0
62
+ private static let earthRadiusMeters: Double = 6371000.0
61
63
 
62
64
  @objc override public func load() {
63
65
  UIDevice.current.isBatteryMonitoringEnabled = true
@@ -74,55 +76,70 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBri
74
76
  }
75
77
  // Create fresh location manager and initialize date
76
78
  self.locationManager = CLLocationManager()
77
- self.locationManager!.delegate = self
79
+ guard let manager = self.locationManager else {
80
+ return call.reject("Failed to create location manager")
81
+ }
82
+ manager.delegate = self
78
83
  self.created = Date()
79
84
 
80
85
  let background = call.getString("backgroundMessage") != nil
81
86
  self.allowStale = call.getBool("stale") ?? false
82
87
  self.activeCallbackId = call.callbackId
83
88
 
84
- let externalPower = [
85
- .full,
86
- .charging
87
- ].contains(UIDevice.current.batteryState)
88
- self.locationManager!.desiredAccuracy = (
89
- externalPower
90
- ? kCLLocationAccuracyBestForNavigation
91
- : kCLLocationAccuracyBest
92
- )
93
- var distanceFilter = call.getDouble("distanceFilter")
94
- // It appears that setting manager.distanceFilter to 0 can prevent
95
- // subsequent location updates. See issue #88.
96
- if distanceFilter == nil || distanceFilter == 0 {
97
- distanceFilter = kCLDistanceFilterNone
98
- }
99
- self.locationManager!.distanceFilter = distanceFilter!
100
- self.locationManager!.allowsBackgroundLocationUpdates = background
101
- self.locationManager!.showsBackgroundLocationIndicator = background
102
- self.locationManager!.pausesLocationUpdatesAutomatically = false
89
+ self.configureLocationManager(manager, call: call, background: background)
103
90
 
104
91
  if call.getBool("requestPermissions") != false {
105
- let status = CLLocationManager.authorizationStatus()
106
- if [
107
- .notDetermined,
108
- .denied,
109
- .restricted
110
- ].contains(status) {
111
- return (
112
- background
113
- ? self.locationManager!.requestAlwaysAuthorization()
114
- : self.locationManager!.requestWhenInUseAuthorization()
115
- )
116
- }
117
- if background && status == .authorizedWhenInUse {
118
- // Attempt to escalate.
119
- self.locationManager!.requestAlwaysAuthorization()
92
+ if self.handlePermissions(manager, background: background) {
93
+ return
120
94
  }
121
95
  }
122
96
  return self.startUpdatingLocation()
123
97
  }
124
98
  }
125
99
 
100
+ private func configureLocationManager(_ manager: CLLocationManager, call: CAPPluginCall, background: Bool) {
101
+ let externalPower = [
102
+ .full,
103
+ .charging
104
+ ].contains(UIDevice.current.batteryState)
105
+ manager.desiredAccuracy = (
106
+ externalPower
107
+ ? kCLLocationAccuracyBestForNavigation
108
+ : kCLLocationAccuracyBest
109
+ )
110
+ var distanceFilter = call.getDouble("distanceFilter")
111
+ // It appears that setting manager.distanceFilter to 0 can prevent
112
+ // subsequent location updates. See issue #88.
113
+ if distanceFilter == nil || distanceFilter == 0 {
114
+ distanceFilter = kCLDistanceFilterNone
115
+ }
116
+ manager.distanceFilter = distanceFilter ?? kCLDistanceFilterNone
117
+ manager.allowsBackgroundLocationUpdates = background
118
+ manager.showsBackgroundLocationIndicator = background
119
+ manager.pausesLocationUpdatesAutomatically = false
120
+ }
121
+
122
+ private func handlePermissions(_ manager: CLLocationManager, background: Bool) -> Bool {
123
+ let status = CLLocationManager.authorizationStatus()
124
+ if [
125
+ .notDetermined,
126
+ .denied,
127
+ .restricted
128
+ ].contains(status) {
129
+ if background {
130
+ manager.requestAlwaysAuthorization()
131
+ } else {
132
+ manager.requestWhenInUseAuthorization()
133
+ }
134
+ return true
135
+ }
136
+ if background && status == .authorizedWhenInUse {
137
+ // Attempt to escalate.
138
+ manager.requestAlwaysAuthorization()
139
+ }
140
+ return false
141
+ }
142
+
126
143
  @objc func stop(_ call: CAPPluginCall) {
127
144
  // CLLocationManager requires main thread
128
145
  DispatchQueue.main.async {
@@ -151,8 +168,7 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBri
151
168
  }
152
169
 
153
170
  if UIApplication.shared.canOpenURL(settingsUrl) {
154
- UIApplication.shared.open(settingsUrl, completionHandler: {
155
- (success) in
171
+ UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
156
172
  if success {
157
173
  return call.resolve()
158
174
  } else {
@@ -252,7 +268,7 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBri
252
268
 
253
269
  let ccc = 2 * atan2(sqrt(aaa), sqrt(1 - aaa))
254
270
 
255
- return BackgroundGeolocation.EARTH_RADIUS_M * ccc
271
+ return BackgroundGeolocation.earthRadiusMeters * ccc
256
272
  }
257
273
 
258
274
  private func distancePointToLineSegment(_ point: [Double], _ lineStart: [Double], _ lineEnd: [Double]) -> Double {
@@ -2,9 +2,10 @@ import XCTest
2
2
  import CoreLocation
3
3
  @testable import CapgoBackgroundGeolocationPlugin
4
4
 
5
+ // swiftlint:disable:next type_body_length
5
6
  class CapgoBackgroundGeolocationTests: XCTestCase {
6
7
 
7
- var plugin: BackgroundGeolocation!
8
+ var plugin: BackgroundGeolocation?
8
9
 
9
10
  override func setUp() {
10
11
  super.setUp()
@@ -19,12 +20,20 @@ class CapgoBackgroundGeolocationTests: XCTestCase {
19
20
  // MARK: - Plugin Initialization Tests
20
21
 
21
22
  func testPluginInitialization() {
23
+ guard let plugin = plugin else {
24
+ XCTFail("Plugin should not be nil")
25
+ return
26
+ }
22
27
  XCTAssertNotNil(plugin)
23
28
  XCTAssertEqual(plugin.identifier, "BackgroundGeolocationPlugin")
24
29
  XCTAssertEqual(plugin.jsName, "BackgroundGeolocation")
25
30
  }
26
31
 
27
32
  func testPluginMethods() {
33
+ guard let plugin = plugin else {
34
+ XCTFail("Plugin should not be nil")
35
+ return
36
+ }
28
37
  let methodNames = plugin.pluginMethods.map { $0.name }
29
38
  XCTAssertTrue(methodNames.contains("start"))
30
39
  XCTAssertTrue(methodNames.contains("stop"))
package/package.json CHANGED
@@ -1,90 +1,90 @@
1
1
  {
2
- "name": "@capgo/background-geolocation",
3
- "version": "7.2.8",
4
- "description": "Receive accurate geolocation updates even while the app is in the background.",
5
- "main": "dist/plugin.cjs.js",
6
- "module": "dist/esm/index.js",
7
- "types": "dist/esm/index.d.ts",
8
- "unpkg": "dist/plugin.js",
9
- "files": [
10
- "android/src/main/",
11
- "android/build.gradle",
12
- "dist/",
13
- "ios/Sources",
14
- "ios/Tests",
15
- "Package.swift",
16
- "CapgoBackgroundGeolocation.podspec"
17
- ],
18
- "author": "Martin Donadieu <martin@capgo.app>",
19
- "license": "MPL-2.0",
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/Cap-go/capacitor-background-geolocation.git"
2
+ "name": "@capgo/background-geolocation",
3
+ "version": "8.0.2",
4
+ "description": "Receive accurate geolocation updates even while the app is in the background.",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Sources",
14
+ "ios/Tests",
15
+ "Package.swift",
16
+ "CapgoBackgroundGeolocation.podspec"
17
+ ],
18
+ "author": "Martin Donadieu <martin@capgo.app>",
19
+ "license": "MPL-2.0",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Cap-go/capacitor-background-geolocation.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/Cap-go/capacitor-background-geolocation/issues"
26
+ },
27
+ "scripts": {
28
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
29
+ "verify:ios": "xcodebuild -scheme CapgoBackgroundGeolocation -destination generic/platform=iOS",
30
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
31
+ "verify:web": "npm run build",
32
+ "test": "npm run test:ios && npm run test:android",
33
+ "test:ios": "./scripts/test-ios.sh",
34
+ "test:android": "cd android && ./gradlew test && cd ..",
35
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37
+ "eslint": "eslint . --ext ts",
38
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
39
+ "swiftlint": "node-swiftlint",
40
+ "docgen": "docgen --api BackgroundGeolocationPlugin --output-readme README.md --output-json dist/docs.json",
41
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
42
+ "clean": "rimraf ./dist",
43
+ "watch": "tsc --watch",
44
+ "prepublishOnly": "npm run build"
45
+ },
46
+ "keywords": [
47
+ "capacitor",
48
+ "plugin",
49
+ "native",
50
+ "accurate",
51
+ "background",
52
+ "geolocation"
53
+ ],
54
+ "devDependencies": {
55
+ "@capacitor/android": "^8.0.0",
56
+ "@capacitor/cli": "^8.0.0",
57
+ "@capacitor/core": "^8.0.0",
58
+ "@capacitor/docgen": "^0.3.1",
59
+ "@capacitor/ios": "^8.0.0",
60
+ "@ionic/eslint-config": "^0.4.0",
61
+ "@ionic/prettier-config": "^4.0.0",
62
+ "@ionic/swiftlint-config": "^2.0.0",
63
+ "@types/node": "^24.10.1",
64
+ "eslint": "^8.57.1",
65
+ "eslint-plugin-import": "^2.31.0",
66
+ "husky": "^9.1.7",
67
+ "prettier": "^3.6.2",
68
+ "prettier-plugin-java": "^2.7.7",
69
+ "rimraf": "^6.1.0",
70
+ "rollup": "^4.53.2",
71
+ "swiftlint": "^2.0.0",
72
+ "typescript": "^5.9.3"
73
+ },
74
+ "peerDependencies": {
75
+ "@capacitor/core": ">=8.0.0"
76
+ },
77
+ "prettier": "@ionic/prettier-config",
78
+ "swiftlint": "@ionic/swiftlint-config",
79
+ "eslintConfig": {
80
+ "extends": "@ionic/eslint-config/recommended"
81
+ },
82
+ "capacitor": {
83
+ "ios": {
84
+ "src": "ios"
23
85
  },
24
- "bugs": {
25
- "url": "https://github.com/Cap-go/capacitor-background-geolocation/issues"
26
- },
27
- "scripts": {
28
- "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
29
- "verify:ios": "xcodebuild -scheme CapgoBackgroundGeolocation -destination generic/platform=iOS",
30
- "verify:android": "cd android && ./gradlew clean build test && cd ..",
31
- "verify:web": "npm run build",
32
- "test": "npm run test:ios && npm run test:android",
33
- "test:ios": "./scripts/test-ios.sh",
34
- "test:android": "cd android && ./gradlew test && cd ..",
35
- "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37
- "eslint": "eslint . --ext ts",
38
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
39
- "swiftlint": "node-swiftlint",
40
- "docgen": "docgen --api BackgroundGeolocationPlugin --output-readme README.md --output-json dist/docs.json",
41
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
42
- "clean": "rimraf ./dist",
43
- "watch": "tsc --watch",
44
- "prepublishOnly": "npm run build"
45
- },
46
- "keywords": [
47
- "capacitor",
48
- "plugin",
49
- "native",
50
- "accurate",
51
- "background",
52
- "geolocation"
53
- ],
54
- "devDependencies": {
55
- "@capacitor/android": "^7.0.0",
56
- "@capacitor/cli": "^7.0.0",
57
- "@capacitor/core": "^7.0.0",
58
- "@capacitor/docgen": "^0.3.0",
59
- "@capacitor/ios": "^7.0.0",
60
- "@ionic/eslint-config": "^0.4.0",
61
- "@ionic/prettier-config": "^4.0.0",
62
- "@ionic/swiftlint-config": "^2.0.0",
63
- "@types/node": "^22.13.1",
64
- "eslint": "^8.57.0",
65
- "eslint-plugin-import": "^2.31.0",
66
- "husky": "^9.1.7",
67
- "prettier": "^3.4.2",
68
- "prettier-plugin-java": "^2.6.7",
69
- "rimraf": "^6.0.1",
70
- "rollup": "^4.34.6",
71
- "swiftlint": "^2.0.0",
72
- "typescript": "^5.7.3"
73
- },
74
- "peerDependencies": {
75
- "@capacitor/core": ">=7.0.0"
76
- },
77
- "prettier": "@ionic/prettier-config",
78
- "swiftlint": "@ionic/swiftlint-config",
79
- "eslintConfig": {
80
- "extends": "@ionic/eslint-config/recommended"
81
- },
82
- "capacitor": {
83
- "ios": {
84
- "src": "ios"
85
- },
86
- "android": {
87
- "src": "android"
88
- }
86
+ "android": {
87
+ "src": "android"
89
88
  }
89
+ }
90
90
  }