@capgo/capacitor-pedometer 7.0.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/CapgoCapacitorPedometer.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +297 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/app/capgo/pedometer/CapacitorPedometerPlugin.java +246 -0
- package/dist/docs.json +455 -0
- package/dist/esm/definitions.d.ts +212 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +10 -0
- package/dist/esm/web.js +28 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +42 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +45 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorPedometerPlugin/CapacitorPedometerPlugin.swift +189 -0
- package/ios/Tests/CapacitorPedometerPluginTests/CapacitorPedometerPluginTests.swift +9 -0
- package/package.json +90 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapacitorPedometerPlugin, GetMeasurementOptions, IsAvailableResult, Measurement, PermissionStatus } from './definitions';
|
|
3
|
+
export declare class CapacitorPedometerWeb extends WebPlugin implements CapacitorPedometerPlugin {
|
|
4
|
+
getMeasurement(_options?: GetMeasurementOptions): Promise<Measurement>;
|
|
5
|
+
isAvailable(): Promise<IsAvailableResult>;
|
|
6
|
+
startMeasurementUpdates(): Promise<void>;
|
|
7
|
+
stopMeasurementUpdates(): Promise<void>;
|
|
8
|
+
checkPermissions(): Promise<PermissionStatus>;
|
|
9
|
+
requestPermissions(): Promise<PermissionStatus>;
|
|
10
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class CapacitorPedometerWeb extends WebPlugin {
|
|
3
|
+
async getMeasurement(_options) {
|
|
4
|
+
throw this.unimplemented('Not implemented on web.');
|
|
5
|
+
}
|
|
6
|
+
async isAvailable() {
|
|
7
|
+
return {
|
|
8
|
+
stepCounting: false,
|
|
9
|
+
distance: false,
|
|
10
|
+
pace: false,
|
|
11
|
+
cadence: false,
|
|
12
|
+
floorCounting: false,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async startMeasurementUpdates() {
|
|
16
|
+
throw this.unimplemented('Not implemented on web.');
|
|
17
|
+
}
|
|
18
|
+
async stopMeasurementUpdates() {
|
|
19
|
+
throw this.unimplemented('Not implemented on web.');
|
|
20
|
+
}
|
|
21
|
+
async checkPermissions() {
|
|
22
|
+
throw this.unimplemented('Not implemented on web.');
|
|
23
|
+
}
|
|
24
|
+
async requestPermissions() {
|
|
25
|
+
throw this.unimplemented('Not implemented on web.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAC,cAAc,CAAC,QAAgC;QACnD,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO;YACL,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,KAAK;YACd,aAAa,EAAE,KAAK;SACrB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,uBAAuB;QAC3B,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorPedometerPlugin,\n GetMeasurementOptions,\n IsAvailableResult,\n Measurement,\n PermissionStatus,\n} from './definitions';\n\nexport class CapacitorPedometerWeb extends WebPlugin implements CapacitorPedometerPlugin {\n async getMeasurement(_options?: GetMeasurementOptions): Promise<Measurement> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async isAvailable(): Promise<IsAvailableResult> {\n return {\n stepCounting: false,\n distance: false,\n pace: false,\n cadence: false,\n floorCounting: false,\n };\n }\n\n async startMeasurementUpdates(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async stopMeasurementUpdates(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const CapacitorPedometer = core.registerPlugin('CapacitorPedometer', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorPedometerWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class CapacitorPedometerWeb extends core.WebPlugin {
|
|
10
|
+
async getMeasurement(_options) {
|
|
11
|
+
throw this.unimplemented('Not implemented on web.');
|
|
12
|
+
}
|
|
13
|
+
async isAvailable() {
|
|
14
|
+
return {
|
|
15
|
+
stepCounting: false,
|
|
16
|
+
distance: false,
|
|
17
|
+
pace: false,
|
|
18
|
+
cadence: false,
|
|
19
|
+
floorCounting: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async startMeasurementUpdates() {
|
|
23
|
+
throw this.unimplemented('Not implemented on web.');
|
|
24
|
+
}
|
|
25
|
+
async stopMeasurementUpdates() {
|
|
26
|
+
throw this.unimplemented('Not implemented on web.');
|
|
27
|
+
}
|
|
28
|
+
async checkPermissions() {
|
|
29
|
+
throw this.unimplemented('Not implemented on web.');
|
|
30
|
+
}
|
|
31
|
+
async requestPermissions() {
|
|
32
|
+
throw this.unimplemented('Not implemented on web.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
37
|
+
__proto__: null,
|
|
38
|
+
CapacitorPedometerWeb: CapacitorPedometerWeb
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
exports.CapacitorPedometer = CapacitorPedometer;
|
|
42
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorPedometer = registerPlugin('CapacitorPedometer', {\n web: () => import('./web').then((m) => new m.CapacitorPedometerWeb()),\n});\nexport * from './definitions';\nexport { CapacitorPedometer };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorPedometerWeb extends WebPlugin {\n async getMeasurement(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async isAvailable() {\n return {\n stepCounting: false,\n distance: false,\n pace: false,\n cadence: false,\n floorCounting: false,\n };\n }\n async startMeasurementUpdates() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopMeasurementUpdates() {\n throw this.unimplemented('Not implemented on web.');\n }\n async checkPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACzE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;AACnC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO;AACf,YAAY,YAAY,EAAE,KAAK;AAC/B,YAAY,QAAQ,EAAE,KAAK;AAC3B,YAAY,IAAI,EAAE,KAAK;AACvB,YAAY,OAAO,EAAE,KAAK;AAC1B,YAAY,aAAa,EAAE,KAAK;AAChC,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,uBAAuB,GAAG;AACpC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,sBAAsB,GAAG;AACnC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var capacitorCapacitorPedometer = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CapacitorPedometer = core.registerPlugin('CapacitorPedometer', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorPedometerWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class CapacitorPedometerWeb extends core.WebPlugin {
|
|
9
|
+
async getMeasurement(_options) {
|
|
10
|
+
throw this.unimplemented('Not implemented on web.');
|
|
11
|
+
}
|
|
12
|
+
async isAvailable() {
|
|
13
|
+
return {
|
|
14
|
+
stepCounting: false,
|
|
15
|
+
distance: false,
|
|
16
|
+
pace: false,
|
|
17
|
+
cadence: false,
|
|
18
|
+
floorCounting: false,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async startMeasurementUpdates() {
|
|
22
|
+
throw this.unimplemented('Not implemented on web.');
|
|
23
|
+
}
|
|
24
|
+
async stopMeasurementUpdates() {
|
|
25
|
+
throw this.unimplemented('Not implemented on web.');
|
|
26
|
+
}
|
|
27
|
+
async checkPermissions() {
|
|
28
|
+
throw this.unimplemented('Not implemented on web.');
|
|
29
|
+
}
|
|
30
|
+
async requestPermissions() {
|
|
31
|
+
throw this.unimplemented('Not implemented on web.');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
36
|
+
__proto__: null,
|
|
37
|
+
CapacitorPedometerWeb: CapacitorPedometerWeb
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
exports.CapacitorPedometer = CapacitorPedometer;
|
|
41
|
+
|
|
42
|
+
return exports;
|
|
43
|
+
|
|
44
|
+
})({}, capacitorExports);
|
|
45
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorPedometer = registerPlugin('CapacitorPedometer', {\n web: () => import('./web').then((m) => new m.CapacitorPedometerWeb()),\n});\nexport * from './definitions';\nexport { CapacitorPedometer };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorPedometerWeb extends WebPlugin {\n async getMeasurement(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n async isAvailable() {\n return {\n stepCounting: false,\n distance: false,\n pace: false,\n cadence: false,\n floorCounting: false,\n };\n }\n async startMeasurementUpdates() {\n throw this.unimplemented('Not implemented on web.');\n }\n async stopMeasurementUpdates() {\n throw this.unimplemented('Not implemented on web.');\n }\n async checkPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACzE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;IACnC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,OAAO;IACf,YAAY,YAAY,EAAE,KAAK;IAC/B,YAAY,QAAQ,EAAE,KAAK;IAC3B,YAAY,IAAI,EAAE,KAAK;IACvB,YAAY,OAAO,EAAE,KAAK;IAC1B,YAAY,aAAa,EAAE,KAAK;IAChC,SAAS;IACT,IAAI;IACJ,IAAI,MAAM,uBAAuB,GAAG;IACpC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,sBAAsB,GAAG;IACnC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import CoreMotion
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
@objc(CapacitorPedometerPlugin)
|
|
6
|
+
public class CapacitorPedometerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
7
|
+
private let PLUGIN_VERSION: String = "7.0.0"
|
|
8
|
+
public let identifier = "CapacitorPedometerPlugin"
|
|
9
|
+
public let jsName = "CapacitorPedometer"
|
|
10
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
11
|
+
CAPPluginMethod(name: "getMeasurement", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "isAvailable", returnType: CAPPluginReturnPromise),
|
|
13
|
+
CAPPluginMethod(name: "startMeasurementUpdates", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "stopMeasurementUpdates", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "checkPermissions", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "requestPermissions", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "removeAllListeners", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
private let pedometer = CMPedometer()
|
|
22
|
+
private var latestMeasurement: [String: Any] = [:]
|
|
23
|
+
|
|
24
|
+
@objc func getMeasurement(_ call: CAPPluginCall) {
|
|
25
|
+
guard CMPedometer.isStepCountingAvailable() else {
|
|
26
|
+
call.reject("Pedometer not available")
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let start = call.getDouble("start")
|
|
31
|
+
let end = call.getDouble("end")
|
|
32
|
+
|
|
33
|
+
guard let startTimestamp = start, let endTimestamp = end else {
|
|
34
|
+
call.reject("Start and end timestamps are required on iOS")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let startDate = Date(timeIntervalSince1970: startTimestamp / 1000)
|
|
39
|
+
let endDate = Date(timeIntervalSince1970: endTimestamp / 1000)
|
|
40
|
+
|
|
41
|
+
pedometer.queryPedometerData(from: startDate, to: endDate) { [weak self] data, error in
|
|
42
|
+
guard let self = self else { return }
|
|
43
|
+
|
|
44
|
+
if let error = error {
|
|
45
|
+
call.reject("Failed to query pedometer data: \(error.localizedDescription)")
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
guard let data = data else {
|
|
50
|
+
call.reject("No pedometer data available")
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let measurement = self.createMeasurementDict(from: data, startDate: startDate, endDate: endDate)
|
|
55
|
+
call.resolve(measurement)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc func isAvailable(_ call: CAPPluginCall) {
|
|
60
|
+
let result: [String: Bool] = [
|
|
61
|
+
"stepCounting": CMPedometer.isStepCountingAvailable(),
|
|
62
|
+
"distance": CMPedometer.isDistanceAvailable(),
|
|
63
|
+
"pace": CMPedometer.isPaceAvailable(),
|
|
64
|
+
"cadence": CMPedometer.isCadenceAvailable(),
|
|
65
|
+
"floorCounting": CMPedometer.isFloorCountingAvailable()
|
|
66
|
+
]
|
|
67
|
+
call.resolve(result)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@objc func startMeasurementUpdates(_ call: CAPPluginCall) {
|
|
71
|
+
guard CMPedometer.isStepCountingAvailable() else {
|
|
72
|
+
call.reject("Pedometer not available")
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let startDate = Date()
|
|
77
|
+
|
|
78
|
+
pedometer.startUpdates(from: startDate) { [weak self] data, error in
|
|
79
|
+
guard let self = self else { return }
|
|
80
|
+
|
|
81
|
+
if let error = error {
|
|
82
|
+
CAPLog.print("CapacitorPedometerPlugin", "Pedometer error: \(error.localizedDescription)")
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
guard let data = data else {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let measurement = self.createMeasurementDict(from: data, startDate: startDate, endDate: Date())
|
|
91
|
+
self.latestMeasurement = measurement
|
|
92
|
+
|
|
93
|
+
DispatchQueue.main.async {
|
|
94
|
+
self.notifyListeners("measurement", data: measurement)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
call.resolve()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@objc func stopMeasurementUpdates(_ call: CAPPluginCall) {
|
|
102
|
+
pedometer.stopUpdates()
|
|
103
|
+
call.resolve()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@objc override public func checkPermissions(_ call: CAPPluginCall) {
|
|
107
|
+
call.resolve(["activityRecognition": currentPermissionState()])
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@objc override public func requestPermissions(_ call: CAPPluginCall) {
|
|
111
|
+
// On iOS, pedometer permissions are requested automatically when starting updates
|
|
112
|
+
// We trigger a brief query to prompt for permission if needed
|
|
113
|
+
let startDate = Date(timeIntervalSinceNow: -1)
|
|
114
|
+
let endDate = Date()
|
|
115
|
+
|
|
116
|
+
pedometer.queryPedometerData(from: startDate, to: endDate) { [weak self] _, _ in
|
|
117
|
+
guard let self = self else { return }
|
|
118
|
+
call.resolve(["activityRecognition": self.currentPermissionState()])
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@objc override public func removeAllListeners(_ call: CAPPluginCall) {
|
|
123
|
+
super.removeAllListeners(call)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private func currentPermissionState() -> String {
|
|
127
|
+
guard CMPedometer.isStepCountingAvailable() else {
|
|
128
|
+
return "denied"
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if #available(iOS 11.0, *) {
|
|
132
|
+
switch CMMotionActivityManager.authorizationStatus() {
|
|
133
|
+
case .authorized:
|
|
134
|
+
return "granted"
|
|
135
|
+
case .denied, .restricted:
|
|
136
|
+
return "denied"
|
|
137
|
+
case .notDetermined:
|
|
138
|
+
return "prompt"
|
|
139
|
+
@unknown default:
|
|
140
|
+
return "prompt"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return "granted"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private func createMeasurementDict(from data: CMPedometerData, startDate: Date, endDate: Date) -> [String: Any] {
|
|
148
|
+
var measurement: [String: Any] = [:]
|
|
149
|
+
|
|
150
|
+
measurement["numberOfSteps"] = data.numberOfSteps.intValue
|
|
151
|
+
|
|
152
|
+
if let distance = data.distance {
|
|
153
|
+
measurement["distance"] = distance.doubleValue
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if let floorsAscended = data.floorsAscended {
|
|
157
|
+
measurement["floorsAscended"] = floorsAscended.intValue
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if let floorsDescended = data.floorsDescended {
|
|
161
|
+
measurement["floorsDescended"] = floorsDescended.intValue
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if #available(iOS 9.0, *) {
|
|
165
|
+
if let currentPace = data.currentPace {
|
|
166
|
+
measurement["currentPace"] = currentPace.doubleValue
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if let currentCadence = data.currentCadence {
|
|
170
|
+
measurement["currentCadence"] = currentCadence.doubleValue
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if #available(iOS 10.0, *) {
|
|
175
|
+
if let averageActivePace = data.averageActivePace {
|
|
176
|
+
measurement["averageActivePace"] = averageActivePace.doubleValue
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
measurement["startDate"] = Int(startDate.timeIntervalSince1970 * 1000)
|
|
181
|
+
measurement["endDate"] = Int(endDate.timeIntervalSince1970 * 1000)
|
|
182
|
+
|
|
183
|
+
return measurement
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
187
|
+
call.resolve(["version": self.PLUGIN_VERSION])
|
|
188
|
+
}
|
|
189
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/capacitor-pedometer",
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "Capacitor plugin for accessing pedometer data including steps, distance, pace, cadence, and floors",
|
|
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
|
+
"CapgoCapacitorPedometer.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "Cap-go <contact@capgo.app>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Cap-go/capacitor-pedometer.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Cap-go/capacitor-pedometer/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native",
|
|
31
|
+
"pedometer",
|
|
32
|
+
"steps",
|
|
33
|
+
"motion",
|
|
34
|
+
"health",
|
|
35
|
+
"fitness",
|
|
36
|
+
"capgo"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
40
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorPedometer -destination generic/platform=iOS",
|
|
41
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
42
|
+
"verify:web": "npm run build",
|
|
43
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
44
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
45
|
+
"eslint": "eslint . --ext .ts",
|
|
46
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
47
|
+
"swiftlint": "node-swiftlint",
|
|
48
|
+
"docgen": "docgen --api CapacitorPedometerPlugin --output-readme README.md --output-json dist/docs.json",
|
|
49
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
50
|
+
"clean": "rimraf ./dist",
|
|
51
|
+
"watch": "tsc --watch",
|
|
52
|
+
"prepublishOnly": "npm run build"
|
|
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
|
+
"eslintConfig": {
|
|
78
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
79
|
+
},
|
|
80
|
+
"prettier": "@ionic/prettier-config",
|
|
81
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
82
|
+
"capacitor": {
|
|
83
|
+
"ios": {
|
|
84
|
+
"src": "ios"
|
|
85
|
+
},
|
|
86
|
+
"android": {
|
|
87
|
+
"src": "android"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|