@josuelmm/cordova-background-geolocation 4.2.3 → 4.5.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.
Files changed (103) hide show
  1. package/.npmignore +11 -0
  2. package/CHANGELOG.md +261 -0
  3. package/README.md +306 -115
  4. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +34 -0
  5. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +61 -1
  6. package/android/common/src/main/AndroidManifest.xml +1 -1
  7. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +20 -3
  8. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +87 -1
  9. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +94 -0
  10. package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
  11. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +6 -0
  12. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +5 -1
  13. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +32 -1
  14. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +12 -2
  15. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +33 -2
  16. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +15 -1
  17. package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +48 -1
  18. package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +105 -6
  19. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +336 -250
  20. package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +69 -19
  21. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +246 -21
  22. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +5 -2
  23. package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +46 -13
  24. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +23 -1
  25. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +208 -70
  26. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +132 -5
  27. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +20 -0
  28. package/ios/common/BackgroundGeolocation/MAURConfig.h +7 -0
  29. package/ios/common/BackgroundGeolocation/MAURConfig.m +37 -2
  30. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +3 -0
  31. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +3 -1
  32. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +10 -1
  33. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +15 -1
  34. package/ios/common/BackgroundGeolocation/MAURLocation.h +12 -0
  35. package/ios/common/BackgroundGeolocation/MAURLocation.m +33 -4
  36. package/ios/common/BackgroundGeolocation/MAURLocationContract.h +4 -0
  37. package/ios/common/BackgroundGeolocation/MAURLocationContract.m +5 -1
  38. package/ios/common/BackgroundGeolocation/MAURLocationManager.m +19 -1
  39. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +9 -0
  40. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +59 -1
  41. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +10 -1
  42. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +54 -4
  43. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +12 -0
  44. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +125 -5
  45. package/package.json +31 -1
  46. package/plugin.xml +3 -10
  47. package/www/BackgroundGeolocation.d.ts +143 -3
  48. package/www/BackgroundGeolocation.js +11 -4
  49. package/CLAUDE.md +0 -56
  50. package/HISTORY.md +0 -871
  51. package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +0 -220
  52. package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +0 -45
  53. package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +0 -570
  54. package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +0 -76
  55. package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +0 -437
  56. package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +0 -95
  57. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +0 -159
  58. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +0 -161
  59. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +0 -247
  60. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +0 -200
  61. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +0 -457
  62. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +0 -96
  63. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +0 -225
  64. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +0 -46
  65. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +0 -14
  66. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +0 -50
  67. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +0 -17
  68. package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +0 -92
  69. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +0 -107
  70. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +0 -5
  71. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +0 -82
  72. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +0 -128
  73. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +0 -191
  74. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +0 -37
  75. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +0 -216
  76. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +0 -223
  77. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +0 -50
  78. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +0 -180
  79. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +0 -16
  80. package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +0 -2
  81. package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +0 -21
  82. package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +0 -135
  83. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +0 -80
  84. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +0 -147
  85. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +0 -30
  86. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +0 -42
  87. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +0 -99
  88. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +0 -327
  89. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +0 -44
  90. package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +0 -94
  91. package/ios/common/BackgroundGeolocationTests/Info.plist +0 -24
  92. package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +0 -185
  93. package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +0 -161
  94. package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +0 -102
  95. package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +0 -216
  96. package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +0 -55
  97. package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +0 -43
  98. package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +0 -102
  99. package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +0 -41
  100. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +0 -240
  101. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +0 -84
  102. package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +0 -144
  103. package/ios/common/scripts/xcode-refactor.js +0 -184
@@ -1,327 +0,0 @@
1
- //
2
- // MotionDetecter.m
3
- // MotionDetection
4
- //
5
- // The MIT License (MIT)
6
- //
7
- // Created by : arturdev
8
- // Copyright (c) 2014 SocialObjects Software. All rights reserved.
9
- //
10
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
11
- // this software and associated documentation files (the "Software"), to deal in
12
- // the Software without restriction, including without limitation the rights to
13
- // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
- // the Software, and to permit persons to whom the Software is furnished to do so,
15
- // subject to the following conditions:
16
- //
17
- // The above copyright notice and this permission notice shall be included in all
18
- // copies or substantial portions of the Software.
19
- //
20
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
- // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
- // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
- // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
- // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
26
-
27
- #import "SOMotionDetector.h"
28
-
29
- CGFloat kMinimumSpeed = 0.3f;
30
- CGFloat kMaximumWalkingSpeed = 1.9f;
31
- CGFloat kMaximumRunningSpeed = 7.5f;
32
- CGFloat kMinimumRunningAcceleration = 3.5f;
33
-
34
- @interface SOMotionDetector()
35
-
36
- @property (strong, nonatomic) NSTimer *shakeDetectingTimer;
37
-
38
- @property (strong, nonatomic) CLLocation *currentLocation;
39
- @property (nonatomic) SOMotionType previousMotionType;
40
-
41
- #pragma mark - Accelerometer manager
42
- @property (strong, nonatomic) CMMotionManager *motionManager;
43
- @property (strong, nonatomic) CMMotionActivityManager *motionActivityManager;
44
-
45
-
46
- @end
47
-
48
- @implementation SOMotionDetector
49
-
50
- + (SOMotionDetector *)sharedInstance
51
- {
52
- static SOMotionDetector *instance = nil;
53
- static dispatch_once_t onceToken;
54
- dispatch_once(&onceToken, ^{
55
- instance = [[self alloc] init];
56
- });
57
-
58
- return instance;
59
- }
60
-
61
- - (id)init
62
- {
63
- self = [super init];
64
- if (self) {
65
- [[NSNotificationCenter defaultCenter] addObserver:self
66
- selector:@selector(handleLocationChangedNotification:)
67
- name:LOCATION_DID_CHANGED_NOTIFICATION
68
- object:nil];
69
- [[NSNotificationCenter defaultCenter] addObserver:self
70
- selector:@selector(handleLocationWasPausedNotification:)
71
- name:LOCATION_WAS_PAUSED_NOTIFICATION
72
- object:nil];
73
- self.activityDetectionInterval = 0.01f;
74
- self.motionManager = [[CMMotionManager alloc] init];
75
- _motionActivity = [[SOMotionActivity alloc] init];
76
- }
77
-
78
- return self;
79
- }
80
-
81
- + (BOOL)motionHardwareAvailable
82
- {
83
- static BOOL isAvailable = NO;
84
- static dispatch_once_t onceToken;
85
- dispatch_once(&onceToken, ^{
86
- isAvailable = [CMMotionActivityManager isActivityAvailable];
87
- });
88
-
89
- return isAvailable;
90
- }
91
-
92
- #pragma mark - Public Methods
93
- - (void)startDetection
94
- {
95
-
96
- [self.motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
97
- withHandler:^(CMAccelerometerData *accelerometerData, NSError *error)
98
- {
99
- _acceleration = accelerometerData.acceleration;
100
- [self calculateMotionType];
101
- dispatch_async(dispatch_get_main_queue(), ^{
102
- #pragma GCC diagnostic push
103
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
104
- if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:accelerationChanged:)]) {
105
- [self.delegate motionDetector:self accelerationChanged:self.acceleration];
106
- }
107
- #pragma GCC diagnostic pop
108
-
109
-
110
- if (self.accelerationChangedBlock) {
111
- self.accelerationChangedBlock (self.acceleration);
112
- }
113
- });
114
- }];
115
-
116
- if (self.useM7IfAvailable && [SOMotionDetector motionHardwareAvailable]) {
117
- if (!self.motionActivityManager) {
118
- self.motionActivityManager = [[CMMotionActivityManager alloc] init];
119
- }
120
-
121
- [self.motionActivityManager startActivityUpdatesToQueue:[[NSOperationQueue alloc] init] withHandler:^(CMMotionActivity *activity) {
122
- dispatch_async(dispatch_get_main_queue(), ^{
123
- SOMotionType motionType;
124
- if (activity.walking) {
125
- motionType = MotionTypeWalking;
126
- } else if (activity.running) {
127
- motionType = MotionTypeRunning;
128
- } else if (activity.automotive) {
129
- motionType = MotionTypeAutomotive;
130
- } else if (activity.stationary || activity.unknown) {
131
- motionType = MotionTypeNotMoving;
132
- } else {
133
- motionType = MotionTypeUnknown;
134
- }
135
-
136
- int confidence;
137
- switch (activity.confidence) {
138
- case CMMotionActivityConfidenceLow:
139
- confidence = 20;
140
- break;
141
- case CMMotionActivityConfidenceMedium:
142
- confidence = 40;
143
- break;
144
- case CMMotionActivityConfidenceHigh:
145
- confidence = 80;
146
- break;
147
- }
148
-
149
- _motionActivity.motionType = motionType;
150
- _motionActivity.confidence = activity.confidence;
151
-
152
- // If type was changed, then call delegate method
153
- if (motionType != self.previousMotionType) {
154
- self.previousMotionType = motionType;
155
- if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:activityTypeChanged:)]) {
156
- [self.delegate motionDetector:self activityTypeChanged:self.motionActivity];
157
- }
158
-
159
- if (self.activityTypeChangedBlock) {
160
- self.activityTypeChangedBlock (self.motionActivity);
161
- }
162
- }
163
- });
164
-
165
- }];
166
- } else {
167
- [[SOLocationManager sharedInstance] start];
168
-
169
- self.shakeDetectingTimer = [NSTimer scheduledTimerWithTimeInterval:self.activityDetectionInterval
170
- target:self
171
- selector:@selector(detectShaking)
172
- userInfo:Nil
173
- repeats:YES];
174
- }
175
- }
176
-
177
- - (void)stopDetection
178
- {
179
- [self.shakeDetectingTimer invalidate];
180
- self.shakeDetectingTimer = nil;
181
-
182
- [[SOLocationManager sharedInstance] stop];
183
- [self.motionManager stopAccelerometerUpdates];
184
- [self.motionActivityManager stopActivityUpdates];
185
- _previousMotionType = 0;
186
- }
187
-
188
- #pragma mark - Customization Methods
189
- - (void)setMinimumSpeed:(CGFloat)speed
190
- {
191
- kMinimumSpeed = speed;
192
- }
193
-
194
- - (void)setMaximumWalkingSpeed:(CGFloat)speed
195
- {
196
- kMaximumWalkingSpeed = speed;
197
- }
198
-
199
- - (void)setMaximumRunningSpeed:(CGFloat)speed
200
- {
201
- kMaximumRunningSpeed = speed;
202
- }
203
-
204
- - (void)setMinimumRunningAcceleration:(CGFloat)acceleration
205
- {
206
- kMinimumRunningAcceleration = acceleration;
207
- }
208
- #pragma mark - Private Methods
209
- - (void)calculateMotionType
210
- {
211
- SOMotionType motionType;
212
- if (_currentSpeed < kMinimumSpeed) {
213
- motionType = MotionTypeNotMoving;
214
- } else if (_currentSpeed <= kMaximumWalkingSpeed) {
215
- motionType = _isShaking ? MotionTypeRunning : MotionTypeWalking;
216
- } else if (_currentSpeed <= kMaximumRunningSpeed) {
217
- motionType = _isShaking ? MotionTypeRunning : MotionTypeAutomotive;
218
- } else {
219
- motionType = MotionTypeAutomotive;
220
- }
221
-
222
- _motionActivity.motionType = motionType;
223
- _motionActivity.confidence = 0;
224
-
225
- // If type was changed, then call delegate method
226
- if (motionType != self.previousMotionType) {
227
- self.previousMotionType = motionType;
228
-
229
- dispatch_async(dispatch_get_main_queue(), ^{
230
- if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:activityTypeChanged:)]) {
231
- [self.delegate motionDetector:self activityTypeChanged:self.motionActivity];
232
- }
233
-
234
- if (self.activityTypeChangedBlock) {
235
- self.activityTypeChangedBlock (self.motionActivity);
236
- }
237
- });
238
- }
239
- }
240
-
241
- - (void)detectShaking
242
- {
243
- //Array for collecting acceleration for last one seconds period.
244
- static NSMutableArray *shakeDataForOneSec = nil;
245
- //Counter for calculating completion of one second interval
246
- static float currentFiringTimeInterval = 0.0f;
247
-
248
- currentFiringTimeInterval += 0.01f;
249
- if (currentFiringTimeInterval < 1.0f) {// if one second time intervall not completed yet
250
- if (!shakeDataForOneSec)
251
- shakeDataForOneSec = [NSMutableArray array];
252
-
253
- // Add current acceleration to array
254
- NSValue *boxedAcceleration = [NSValue value:&_acceleration withObjCType:@encode(CMAcceleration)];
255
- [shakeDataForOneSec addObject:boxedAcceleration];
256
- } else {
257
- // Now, when one second was elapsed, calculate shake count in this interval. If there will be at least one shake then
258
- // we'll determine it as shaked in all this one second interval.
259
-
260
- int shakeCount = 0;
261
- for (NSValue *boxedAcceleration in shakeDataForOneSec) {
262
- CMAcceleration acceleration;
263
- [boxedAcceleration getValue:&acceleration];
264
-
265
- /*********************************
266
- * Detecting shaking
267
- *********************************/
268
- double accX_2 = powf(acceleration.x,2);
269
- double accY_2 = powf(acceleration.y,2);
270
- double accZ_2 = powf(acceleration.z,2);
271
-
272
- double vectorSum = sqrt(accX_2 + accY_2 + accZ_2);
273
-
274
- if (vectorSum >= kMinimumRunningAcceleration) {
275
- shakeCount++;
276
- }
277
- /*********************************/
278
- }
279
- _isShaking = shakeCount > 0;
280
-
281
- shakeDataForOneSec = nil;
282
- currentFiringTimeInterval = 0.0f;
283
- }
284
- }
285
-
286
- #pragma mark - LocationManager notification handler
287
- - (void)handleLocationChangedNotification:(NSNotification *)note
288
- {
289
- self.currentLocation = [SOLocationManager sharedInstance].lastLocation;
290
- _currentSpeed = self.currentLocation.speed;
291
- if (_currentSpeed < 0) {
292
- _currentSpeed = 0;
293
- }
294
-
295
- dispatch_async(dispatch_get_main_queue(), ^{
296
- #pragma GCC diagnostic push
297
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
298
- if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:locationChanged:)]) {
299
- [self.delegate motionDetector:self locationChanged:self.currentLocation];
300
- }
301
- #pragma GCC diagnostic pop
302
-
303
- if (self.locationChangedBlock) {
304
- self.locationChangedBlock (self.currentLocation);
305
- }
306
- });
307
-
308
- [self calculateMotionType];
309
- }
310
-
311
- #pragma mark - LocationManager notification handler
312
- - (void)handleLocationWasPausedNotification:(NSNotification *)note
313
- {
314
- dispatch_async(dispatch_get_main_queue(), ^{
315
- #pragma GCC diagnostic push
316
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
317
- if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:locationWasPaused:)]) {
318
- [self.delegate motionDetector:self locationWasPaused:TRUE];
319
- }
320
- #pragma GCC diagnostic pop
321
-
322
- if (self.locationWasPausedBlock) {
323
- self.locationWasPausedBlock (TRUE);
324
- }
325
- });
326
- }
327
- @end
@@ -1,44 +0,0 @@
1
- //
2
- // SOMotionDetecter.h
3
- // MotionDetection
4
- //
5
- // The MIT License (MIT)
6
- //
7
- // Created by : arturdev
8
- // Copyright (c) 2014 SocialObjects Software. All rights reserved.
9
- //
10
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
11
- // this software and associated documentation files (the "Software"), to deal in
12
- // the Software without restriction, including without limitation the rights to
13
- // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
- // the Software, and to permit persons to whom the Software is furnished to do so,
15
- // subject to the following conditions:
16
- //
17
- // The above copyright notice and this permission notice shall be included in all
18
- // copies or substantial portions of the Software.
19
- //
20
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
- // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
- // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
- // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
- // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
26
-
27
- #import <Foundation/Foundation.h>
28
-
29
- @interface SOStepDetector : NSObject
30
-
31
- + (instancetype)sharedInstance;
32
-
33
- /**
34
- * Start accelerometer updates.
35
- * @param callback Will be called every time when new step is detected
36
- */
37
- - (void)startDetectionWithUpdateBlock:(void(^)(NSError *error))callback;
38
-
39
- /**
40
- * Stop motion manager accelerometer updates
41
- */
42
- - (void)stopDetection;
43
-
44
- @end
@@ -1,94 +0,0 @@
1
-
2
- //
3
- // SOStepDetector.m
4
- // MotionDetection
5
- //
6
- // Created by Artur on 5/15/15.
7
- // Copyright (c) 2015 Artur Mkrtchyan. All rights reserved.
8
- //
9
-
10
- #import <UIKit/UIKit.h>
11
- #import "SOStepDetector.h"
12
- #import <CoreMotion/CoreMotion.h>
13
-
14
- #define kUpdateInterval 0.2f
15
- @interface SOStepDetector()
16
-
17
- @property (strong, nonatomic) CMMotionManager *motionManager;
18
- @property (strong, nonatomic) NSOperationQueue* queue;
19
-
20
- @end
21
-
22
- @implementation SOStepDetector
23
-
24
- + (instancetype)sharedInstance
25
- {
26
- static id instance;
27
- static dispatch_once_t onceToken;
28
- dispatch_once(&onceToken, ^{
29
- instance = [self new];
30
- });
31
-
32
- return instance;
33
- }
34
-
35
- - (instancetype)init
36
- {
37
- self = [super init];
38
-
39
- self.motionManager = [CMMotionManager new];
40
-
41
- self.motionManager.accelerometerUpdateInterval = kUpdateInterval;
42
- self.motionManager.deviceMotionUpdateInterval = kUpdateInterval;
43
- self.motionManager.gyroUpdateInterval = kUpdateInterval;
44
- self.motionManager.magnetometerUpdateInterval = kUpdateInterval;
45
- self.motionManager.showsDeviceMovementDisplay = YES;
46
-
47
- self.queue = [NSOperationQueue new];
48
- self.queue.maxConcurrentOperationCount = 1;
49
-
50
- return self;
51
- }
52
-
53
- - (void)startDetectionWithUpdateBlock:(void (^)(NSError *))callback
54
- {
55
- if (self.motionManager.isAccelerometerActive) {
56
- return;
57
- }
58
-
59
- [self.motionManager startAccelerometerUpdatesToQueue:self.queue
60
- withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
61
- if (error) {
62
- if (callback) {
63
- dispatch_async(dispatch_get_main_queue(), ^{
64
- callback (error);
65
- });
66
- }
67
- return ;
68
- }
69
-
70
- CMAcceleration acceleration = accelerometerData.acceleration;
71
-
72
- CGFloat strength = 1.2f;
73
- BOOL isStep = NO;
74
- if (fabs(acceleration.x) > strength || fabs(acceleration.y) > strength || fabs(acceleration.z) > strength) {
75
- isStep = YES;
76
- }
77
- if (isStep) {
78
- if (callback) {
79
- dispatch_async(dispatch_get_main_queue(), ^{
80
- callback (nil);
81
- });
82
- }
83
- }
84
- }];
85
- }
86
-
87
- - (void)stopDetection
88
- {
89
- if (self.motionManager.isAccelerometerActive) {
90
- [self.motionManager stopAccelerometerUpdates];
91
- }
92
- }
93
-
94
- @end
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>CFBundleDevelopmentRegion</key>
6
- <string>en</string>
7
- <key>CFBundleExecutable</key>
8
- <string>$(EXECUTABLE_NAME)</string>
9
- <key>CFBundleIdentifier</key>
10
- <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
- <key>CFBundleInfoDictionaryVersion</key>
12
- <string>6.0</string>
13
- <key>CFBundleName</key>
14
- <string>$(PRODUCT_NAME)</string>
15
- <key>CFBundlePackageType</key>
16
- <string>BNDL</string>
17
- <key>CFBundleShortVersionString</key>
18
- <string>1.0</string>
19
- <key>CFBundleSignature</key>
20
- <string>????</string>
21
- <key>CFBundleVersion</key>
22
- <string>1</string>
23
- </dict>
24
- </plist>
@@ -1,185 +0,0 @@
1
- //
2
- // MAURBackgroundLocationTest.m
3
- // BackgroundGeolocationTests
4
- //
5
- // Created by Marian Hello on 12/06/16.
6
- // Copyright © 2016 mauron85. All rights reserved.
7
- //
8
-
9
- #import <XCTest/XCTest.h>
10
- #import "MAURLocation.h"
11
-
12
- @interface MAURBackgroundLocationTest : XCTestCase
13
-
14
- @end
15
-
16
- @implementation MAURBackgroundLocationTest
17
-
18
- - (void)setUp {
19
- [super setUp];
20
- // Put setup code here. This method is called before the invocation of each test method in the class.
21
- }
22
-
23
- - (void)tearDown {
24
- // Put teardown code here. This method is called after the invocation of each test method in the class.
25
- [super tearDown];
26
- }
27
-
28
- - (void)testTimeToDictionary {
29
- NSDateFormatter *RFC3339DateFormatter = [[NSDateFormatter alloc] init];
30
- RFC3339DateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
31
- RFC3339DateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
32
- RFC3339DateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
33
- NSString *string = @"2016-01-01T00:00:00+01:00";
34
-
35
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
36
- bgloc1.time = [RFC3339DateFormatter dateFromString:string];
37
-
38
- NSDictionary *data = [bgloc1 toDictionary];
39
-
40
- XCTAssertEqual([[data objectForKey:@"time"] doubleValue], 1451602800000);
41
- XCTAssertEqual([bgloc1.time timeIntervalSince1970] * 1000, 1451602800000);
42
- }
43
-
44
- - (void)testObjectCopying {
45
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
46
- bgloc1.latitude = [NSNumber numberWithDouble:12];
47
- bgloc1.longitude = [NSNumber numberWithDouble:11];
48
- bgloc1.radius = [NSNumber numberWithDouble:50];
49
-
50
- MAURLocation *stationaryLocation = [bgloc1 copy];
51
- // stationaryLocation.type = @"stationary";
52
-
53
- XCTAssertTrue([bgloc1.radius isEqualToNumber:[NSNumber numberWithDouble:50]]);
54
- // XCTAssertTrue([stationaryLocation.type isEqualToString:@"stationary"]);
55
- }
56
-
57
- - (void)testDistanceFromLocation {
58
- // This is an example of a functional test case.
59
- // Use XCTAssert and related functions to verify your tests produce the correct results.
60
- const double latitude1 = 49.1634594;
61
- const double longitude1 = 20.273454;
62
- const double latitude2 = 49.1260825;
63
- const double longitude2 = 20.4350187;
64
-
65
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
66
- MAURLocation *bgloc2 = [[MAURLocation alloc] init];
67
- bgloc1.latitude = [NSNumber numberWithDouble:latitude1];
68
- bgloc1.longitude = [NSNumber numberWithDouble:longitude1];
69
- bgloc2.latitude = [NSNumber numberWithDouble:latitude2];
70
- bgloc2.longitude = [NSNumber numberWithDouble:longitude2];
71
-
72
- CLLocation *location1 = [[CLLocation alloc]initWithLatitude:latitude1 longitude:longitude1];
73
- CLLocation *location2 = [[CLLocation alloc]initWithLatitude:latitude2 longitude:longitude2];
74
-
75
- double apple_dist = [location1 distanceFromLocation:location2];
76
- double bgloc_dist = [bgloc1 distanceFromLocation:bgloc2];
77
- XCTAssertEqualWithAccuracy(bgloc_dist, apple_dist, 20, "Our implementation of distance %f should equal Apple %f", bgloc_dist, apple_dist);
78
- }
79
-
80
- - (void)testLocationIsBeyond {
81
- // Use XCTAssert and related functions to verify your tests produce the correct results.
82
- const double latitude1 = 49.134873;
83
- const double longitude1 = 20.209260;
84
- const double latitude2 = 49.14088;
85
- const double longitude2 = 20.225382;
86
-
87
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
88
- MAURLocation *bgloc2 = [[MAURLocation alloc] init];
89
- bgloc1.latitude = [NSNumber numberWithDouble:latitude1];
90
- bgloc1.longitude = [NSNumber numberWithDouble:longitude1];
91
- bgloc2.latitude = [NSNumber numberWithDouble:latitude2];
92
- bgloc2.longitude = [NSNumber numberWithDouble:longitude2];
93
-
94
- XCTAssertTrue([bgloc1 isBeyond:bgloc2 radius:100], "Expecting bgloc1 to not be beyond bgloc2 and radius 100m");
95
- XCTAssertTrue([bgloc1 isBeyond:bgloc2 radius:1000], "Expecting bgloc1 to not be beyond bgloc2 and radius 1000m");
96
- XCTAssertTrue(![bgloc1 isBeyond:bgloc2 radius:10000], "Expecting bgloc1 to be beyond bgloc2 and radius 10000m");
97
- }
98
-
99
- - (void)testIfSignificantlyNewerLocationIsBetter {
100
- const double latitude1 = 49.134873;
101
- const double longitude1 = 20.209260;
102
- const double latitude2 = 49.14088;
103
- const double longitude2 = 20.225382;
104
- const int oldtime = 1451602800; //Fri Jan 01 2016 00:00:00 GMT+0100 (CET)
105
- const int newtime = 1451610000; //Fri Jan 01 2016 00:02:00 GMT+0100 (CET)
106
-
107
- MAURLocation *older = [[MAURLocation alloc] init];
108
- MAURLocation *newer = [[MAURLocation alloc] init];
109
- older.latitude = [NSNumber numberWithDouble:latitude1];
110
- older.longitude = [NSNumber numberWithDouble:longitude1];
111
- older.time = [[NSDate alloc]initWithTimeIntervalSince1970:oldtime];
112
- newer.latitude = [NSNumber numberWithDouble:latitude2];
113
- newer.longitude = [NSNumber numberWithDouble:longitude2];
114
- newer.time = [[NSDate alloc]initWithTimeIntervalSince1970:newtime];
115
-
116
- XCTAssertTrue([newer isBetterLocation:older]);
117
- }
118
-
119
- - (void)testIfLocationWithBetterAccuracyAndSameTimeIsBetter {
120
- const double latitude1 = 49.134873;
121
- const double longitude1 = 20.209260;
122
- const double latitude2 = 49.14088;
123
- const double longitude2 = 20.225382;
124
- const double accuracy = 400;
125
- const double betterAccuracy = 100;
126
- const int time = 1451602800;
127
-
128
- MAURLocation *lessAccurate = [[MAURLocation alloc] init];
129
- MAURLocation *moreAccurate = [[MAURLocation alloc] init];
130
- lessAccurate.latitude = [NSNumber numberWithDouble:latitude1];
131
- lessAccurate.longitude = [NSNumber numberWithDouble:longitude1];
132
- lessAccurate.time = [[NSDate alloc]initWithTimeIntervalSince1970:time];
133
- lessAccurate.accuracy = [NSNumber numberWithDouble:accuracy];
134
- moreAccurate.latitude = [NSNumber numberWithDouble:latitude2];
135
- moreAccurate.longitude = [NSNumber numberWithDouble:longitude2];
136
- moreAccurate.time = [[NSDate alloc]initWithTimeIntervalSince1970:time];
137
- moreAccurate.accuracy = [NSNumber numberWithDouble:betterAccuracy];
138
-
139
- XCTAssertTrue([moreAccurate isBetterLocation:lessAccurate]);
140
- }
141
-
142
- - (void)testIflLocationWithNilAccuracyIsInvalid
143
- {
144
- MAURLocation *loc = [[MAURLocation alloc] init];
145
- XCTAssertFalse([loc hasAccuracy]);
146
- }
147
-
148
- - (void) testIfLocationWithZeroAccuracyIsInvalid
149
- {
150
- MAURLocation *loc = [[MAURLocation alloc] init];
151
- loc.accuracy = [NSNumber numberWithInt:0];
152
- XCTAssertTrue([loc hasAccuracy]);
153
- }
154
-
155
- - (void) testIfLocationWithAccuracyAboveZeroIsValid
156
- {
157
- MAURLocation *loc = [[MAURLocation alloc] init];
158
- loc.accuracy = [NSNumber numberWithInt:10];
159
- XCTAssertTrue([loc isValid]);
160
- }
161
-
162
- - (void)testIflLocationWithTimeMoreThenOneDayFromNowIsInvalid
163
- {
164
- MAURLocation *loc = [[MAURLocation alloc] init];
165
- loc.accuracy = [[NSNumber alloc] initWithInt:1];
166
- loc.time = [[[NSDate alloc] init] dateByAddingTimeInterval:186400];
167
- XCTAssertTrue(![loc hasTime]);
168
- }
169
-
170
- - (void)testIflLocationWithTimeNowIsValid
171
- {
172
- MAURLocation *loc = [[MAURLocation alloc] init];
173
- loc.accuracy = [[NSNumber alloc] initWithInt:1];
174
- loc.time = [[NSDate alloc] init];
175
- XCTAssertTrue([loc isValid]);
176
- }
177
-
178
- - (void)testPerformanceExample {
179
- // This is an example of a performance test case.
180
- [self measureBlock:^{
181
- // Put the code you want to measure the time of here.
182
- }];
183
- }
184
-
185
- @end