@josuelmm/cordova-background-geolocation 4.5.2 → 4.5.5

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 (66) hide show
  1. package/.npmignore +47 -47
  2. package/CHANGELOG.md +26 -0
  3. package/CONTRIBUTORS.md +15 -15
  4. package/LICENSE +191 -191
  5. package/README.md +5 -5
  6. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +2 -2
  7. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +1 -1
  8. package/android/common/src/main/AndroidManifest.xml +76 -76
  9. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +1 -1
  10. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +6 -6
  11. package/android/common/src/main/java/com/marianhello/bgloc/HttpPostService.java +21 -1
  12. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +7 -0
  13. package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +2 -2
  14. package/android/common/src/main/java/com/marianhello/bgloc/data/SessionLocationDAO.java +18 -18
  15. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionContract.java +74 -74
  16. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionLocationDAO.java +169 -169
  17. package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +4 -4
  18. package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +7 -7
  19. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +7 -7
  20. package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +5 -5
  21. package/angular/background-geolocation-enums.ts +63 -63
  22. package/angular/background-geolocation-events.ts +38 -38
  23. package/angular/background-geolocation.module.ts +29 -29
  24. package/angular/dist/esm2022/background-geolocation-enums.mjs +1 -1
  25. package/angular/dist/esm2022/background-geolocation-events.mjs +1 -1
  26. package/angular/dist/esm2022/background-geolocation.module.mjs +1 -1
  27. package/angular/dist/fesm2022/josuelmm-cordova-background-geolocation.mjs.map +1 -1
  28. package/angular/tsconfig.json +18 -18
  29. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +1 -1
  30. package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.h +0 -0
  31. package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.m +0 -0
  32. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager+Internal.h +0 -0
  33. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.h +0 -0
  34. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.m +0 -0
  35. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.h +0 -0
  36. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.m +0 -0
  37. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequestDefines.h +0 -0
  38. package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.h +0 -0
  39. package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.m +0 -0
  40. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +6 -6
  41. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +2 -2
  42. package/ios/common/BackgroundGeolocation/MAURConfig.h +1 -1
  43. package/ios/common/BackgroundGeolocation/MAURConfig.m +2 -2
  44. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +1 -1
  45. package/ios/common/BackgroundGeolocation/MAURLocation.m +7 -0
  46. package/ios/common/BackgroundGeolocation/MAURLocationManager.m +1 -1
  47. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +17 -1
  48. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +1 -1
  49. package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.h +29 -29
  50. package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.m +31 -31
  51. package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.h +25 -25
  52. package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.m +153 -153
  53. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/README.md +0 -0
  54. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.h +0 -0
  55. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.m +0 -0
  56. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlDataManipulationCommand.h +0 -0
  57. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.h +0 -0
  58. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.m +0 -0
  59. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.h +0 -0
  60. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.m +0 -0
  61. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlStatement.h +0 -0
  62. package/package.json +1 -1
  63. package/plugin.xml +1 -1
  64. package/www/BackgroundGeolocation.d.ts +4 -4
  65. package/www/cordova-channel-stub.js +27 -27
  66. package/www/cordova-exec-stub.js +15 -15
@@ -532,7 +532,7 @@ enum {
532
532
  DDLogInfo(@"Destroying %@ ", TAG);
533
533
  [self onStop:nil];
534
534
 
535
- // v4.5.2: release our delegate slot so a CLLocationManager retained by the
535
+ // v4.5.4: release our delegate slot so a CLLocationManager retained by the
536
536
  // OS (e.g. while a stationary region monitor is still alive briefly after
537
537
  // stop) cannot deliver callbacks to a destroyed provider.
538
538
  if (locationManager != nil && locationManager.delegate == self) {
@@ -205,6 +205,13 @@ enum {
205
205
  if ([key isEqualToString:@"@time"]) {
206
206
  return [NSNumber numberWithDouble:([time timeIntervalSince1970] * 1000)];
207
207
  }
208
+ // v4.5.4 — Unix epoch in SECONDS (not ms). Useful for Traccar OsmAnd
209
+ // protocol and backends that treat 13-digit millis as garbage and silently
210
+ // fall back to server time, dropping the real GPS fix time.
211
+ if ([key isEqualToString:@"@time_seconds"]) {
212
+ if (time == nil) return [NSNull null];
213
+ return [NSNumber numberWithLongLong:(long long)[time timeIntervalSince1970]];
214
+ }
208
215
  if ([key isEqualToString:@"@accuracy"]) {
209
216
  return accuracy;
210
217
  }
@@ -213,7 +213,7 @@ static NSString *const Domain = @"com.marianhello";
213
213
  }
214
214
  }
215
215
 
216
- // v4.5.2: iOS 14+ delegate callback. The legacy
216
+ // v4.5.4: iOS 14+ delegate callback. The legacy
217
217
  // `locationManager:didChangeAuthorizationStatus:` is deprecated in iOS 14 but
218
218
  // still delivered alongside this one, so we ignore the legacy variant when
219
219
  // running on iOS 14+ to avoid double-notifying delegates (RAW + ACTIVITY
@@ -243,7 +243,23 @@ static MAURLocationTransform s_locationTransform = nil;
243
243
  if (dict) {
244
244
  NSMutableArray *parts = [NSMutableArray array];
245
245
  for (NSString *key in dict) {
246
- NSString *value = [NSString stringWithFormat:@"%@", dict[key]];
246
+ // v4.5.4: skip null / NSNull values. Previously they were
247
+ // serialized as the literal "<null>" string, which servers
248
+ // like Traccar reject (HTTP 400 — OsmAndProtocolDecoder
249
+ // throws NumberFormatException on "speed=null"). Placeholders
250
+ // that resolve to no value (@speed, @events, @battery, etc.)
251
+ // end up as NSNull in the parsed dict and must be omitted
252
+ // from form-urlencoded bodies.
253
+ id raw = dict[key];
254
+ if (raw == nil || raw == [NSNull null]) {
255
+ continue;
256
+ }
257
+ NSString *value = [NSString stringWithFormat:@"%@", raw];
258
+ // Extra safety: some stringifications produce the literal
259
+ // "null" or "<null>" string. Treat as missing value.
260
+ if ([@"null" isEqualToString:value] || [@"<null>" isEqualToString:value]) {
261
+ continue;
262
+ }
247
263
  NSString *encodedKey = [key stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
248
264
  NSString *encodedValue = [value stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
249
265
  NSString *part = [NSString stringWithFormat:@"%@=%@", encodedKey, encodedValue];
@@ -119,7 +119,7 @@ static NSString * const Domain = @"com.marianhello";
119
119
  DDLogInfo(@"Destroying %@ ", TAG);
120
120
  [self onStop:nil];
121
121
 
122
- // v4.5.2: MAURLocationManager is a singleton shared with the other providers.
122
+ // v4.5.4: MAURLocationManager is a singleton shared with the other providers.
123
123
  // Release our delegate slot so a later provider swap does not leave this
124
124
  // (already destroyed) instance as the active delegate.
125
125
  if (locationManager != nil && locationManager.delegate == self) {
@@ -1,29 +1,29 @@
1
- //
2
- // MAURSessionLocationContract.h
3
- // BackgroundGeolocation
4
- //
5
- // Session table for current recording route. Independent of sync; cleared on startSession/clearSession.
6
- //
7
-
8
- #ifndef MAURSessionLocationContract_h
9
- #define MAURSessionLocationContract_h
10
-
11
- #define LSC_TABLE_NAME "location_session"
12
- #define LSC_COLUMN_NAME_ID "id"
13
- #define LSC_COLUMN_NAME_TIME "time"
14
- #define LSC_COLUMN_NAME_ACCURACY "accuracy"
15
- #define LSC_COLUMN_NAME_SPEED "speed"
16
- #define LSC_COLUMN_NAME_BEARING "bearing"
17
- #define LSC_COLUMN_NAME_ALTITUDE "altitude"
18
- #define LSC_COLUMN_NAME_LATITUDE "latitude"
19
- #define LSC_COLUMN_NAME_LONGITUDE "longitude"
20
- #define LSC_COLUMN_NAME_PROVIDER "provider"
21
- #define LSC_COLUMN_NAME_LOCATION_PROVIDER "service_provider"
22
- #define LSC_COLUMN_NAME_STATUS "valid"
23
- #define LSC_COLUMN_NAME_RECORDED_AT "recorded_at"
24
-
25
- @interface MAURSessionLocationContract : NSObject
26
- + (NSString*) createTableSQL;
27
- @end
28
-
29
- #endif /* MAURSessionLocationContract_h */
1
+ //
2
+ // MAURSessionLocationContract.h
3
+ // BackgroundGeolocation
4
+ //
5
+ // Session table for current recording route. Independent of sync; cleared on startSession/clearSession.
6
+ //
7
+
8
+ #ifndef MAURSessionLocationContract_h
9
+ #define MAURSessionLocationContract_h
10
+
11
+ #define LSC_TABLE_NAME "location_session"
12
+ #define LSC_COLUMN_NAME_ID "id"
13
+ #define LSC_COLUMN_NAME_TIME "time"
14
+ #define LSC_COLUMN_NAME_ACCURACY "accuracy"
15
+ #define LSC_COLUMN_NAME_SPEED "speed"
16
+ #define LSC_COLUMN_NAME_BEARING "bearing"
17
+ #define LSC_COLUMN_NAME_ALTITUDE "altitude"
18
+ #define LSC_COLUMN_NAME_LATITUDE "latitude"
19
+ #define LSC_COLUMN_NAME_LONGITUDE "longitude"
20
+ #define LSC_COLUMN_NAME_PROVIDER "provider"
21
+ #define LSC_COLUMN_NAME_LOCATION_PROVIDER "service_provider"
22
+ #define LSC_COLUMN_NAME_STATUS "valid"
23
+ #define LSC_COLUMN_NAME_RECORDED_AT "recorded_at"
24
+
25
+ @interface MAURSessionLocationContract : NSObject
26
+ + (NSString*) createTableSQL;
27
+ @end
28
+
29
+ #endif /* MAURSessionLocationContract_h */
@@ -1,31 +1,31 @@
1
- //
2
- // MAURSessionLocationContract.m
3
- // BackgroundGeolocation
4
- //
5
-
6
- #import <Foundation/Foundation.h>
7
- #import "MAURSQLiteHelper.h"
8
- #import "MAURSessionLocationContract.h"
9
-
10
- @implementation MAURSessionLocationContract
11
-
12
- + (NSString*) createTableSQL
13
- {
14
- NSArray *columns = @[
15
- @{ @"name": @LSC_COLUMN_NAME_ID, @"type": [SQLPrimaryKeyAutoIncColumnType sqlColumnWithType: kInteger]},
16
- @{ @"name": @LSC_COLUMN_NAME_TIME, @"type": [SQLColumnType sqlColumnWithType: kReal]},
17
- @{ @"name": @LSC_COLUMN_NAME_ACCURACY, @"type": [SQLColumnType sqlColumnWithType: kReal]},
18
- @{ @"name": @LSC_COLUMN_NAME_SPEED, @"type": [SQLColumnType sqlColumnWithType: kReal]},
19
- @{ @"name": @LSC_COLUMN_NAME_BEARING, @"type": [SQLColumnType sqlColumnWithType: kReal]},
20
- @{ @"name": @LSC_COLUMN_NAME_ALTITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]},
21
- @{ @"name": @LSC_COLUMN_NAME_LATITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]},
22
- @{ @"name": @LSC_COLUMN_NAME_LONGITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]},
23
- @{ @"name": @LSC_COLUMN_NAME_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kText]},
24
- @{ @"name": @LSC_COLUMN_NAME_LOCATION_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kText]},
25
- @{ @"name": @LSC_COLUMN_NAME_STATUS, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
26
- @{ @"name": @LSC_COLUMN_NAME_RECORDED_AT, @"type": [SQLColumnType sqlColumnWithType: kInteger]}
27
- ];
28
- return [MAURSQLiteHelper createTableSqlStatement:@LSC_TABLE_NAME columns:columns];
29
- }
30
-
31
- @end
1
+ //
2
+ // MAURSessionLocationContract.m
3
+ // BackgroundGeolocation
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import "MAURSQLiteHelper.h"
8
+ #import "MAURSessionLocationContract.h"
9
+
10
+ @implementation MAURSessionLocationContract
11
+
12
+ + (NSString*) createTableSQL
13
+ {
14
+ NSArray *columns = @[
15
+ @{ @"name": @LSC_COLUMN_NAME_ID, @"type": [SQLPrimaryKeyAutoIncColumnType sqlColumnWithType: kInteger]},
16
+ @{ @"name": @LSC_COLUMN_NAME_TIME, @"type": [SQLColumnType sqlColumnWithType: kReal]},
17
+ @{ @"name": @LSC_COLUMN_NAME_ACCURACY, @"type": [SQLColumnType sqlColumnWithType: kReal]},
18
+ @{ @"name": @LSC_COLUMN_NAME_SPEED, @"type": [SQLColumnType sqlColumnWithType: kReal]},
19
+ @{ @"name": @LSC_COLUMN_NAME_BEARING, @"type": [SQLColumnType sqlColumnWithType: kReal]},
20
+ @{ @"name": @LSC_COLUMN_NAME_ALTITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]},
21
+ @{ @"name": @LSC_COLUMN_NAME_LATITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]},
22
+ @{ @"name": @LSC_COLUMN_NAME_LONGITUDE, @"type": [SQLColumnType sqlColumnWithType: kReal]},
23
+ @{ @"name": @LSC_COLUMN_NAME_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kText]},
24
+ @{ @"name": @LSC_COLUMN_NAME_LOCATION_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kText]},
25
+ @{ @"name": @LSC_COLUMN_NAME_STATUS, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
26
+ @{ @"name": @LSC_COLUMN_NAME_RECORDED_AT, @"type": [SQLColumnType sqlColumnWithType: kInteger]}
27
+ ];
28
+ return [MAURSQLiteHelper createTableSqlStatement:@LSC_TABLE_NAME columns:columns];
29
+ }
30
+
31
+ @end
@@ -1,25 +1,25 @@
1
- //
2
- // MAURSessionLocationDAO.h
3
- // BackgroundGeolocation
4
- //
5
- // Session storage for current route. Cleared on startSession/clearSession; not cleared by sync.
6
- //
7
-
8
- #ifndef MAURSessionLocationDAO_h
9
- #define MAURSessionLocationDAO_h
10
-
11
- #import <Foundation/Foundation.h>
12
- #import "MAURLocation.h"
13
-
14
- @interface MAURSessionLocationDAO : NSObject
15
- + (instancetype) sharedInstance;
16
- - (id) init NS_UNAVAILABLE;
17
- - (void) startSession;
18
- - (void) clearSession;
19
- - (BOOL) isSessionActive;
20
- - (void) persistSessionLocation:(MAURLocation*)location;
21
- - (NSArray<MAURLocation*>*) getSessionLocations;
22
- - (NSInteger) getSessionLocationsCount;
23
- @end
24
-
25
- #endif /* MAURSessionLocationDAO_h */
1
+ //
2
+ // MAURSessionLocationDAO.h
3
+ // BackgroundGeolocation
4
+ //
5
+ // Session storage for current route. Cleared on startSession/clearSession; not cleared by sync.
6
+ //
7
+
8
+ #ifndef MAURSessionLocationDAO_h
9
+ #define MAURSessionLocationDAO_h
10
+
11
+ #import <Foundation/Foundation.h>
12
+ #import "MAURLocation.h"
13
+
14
+ @interface MAURSessionLocationDAO : NSObject
15
+ + (instancetype) sharedInstance;
16
+ - (id) init NS_UNAVAILABLE;
17
+ - (void) startSession;
18
+ - (void) clearSession;
19
+ - (BOOL) isSessionActive;
20
+ - (void) persistSessionLocation:(MAURLocation*)location;
21
+ - (NSArray<MAURLocation*>*) getSessionLocations;
22
+ - (NSInteger) getSessionLocationsCount;
23
+ @end
24
+
25
+ #endif /* MAURSessionLocationDAO_h */
@@ -1,153 +1,153 @@
1
- //
2
- // MAURSessionLocationDAO.m
3
- // BackgroundGeolocation
4
- //
5
-
6
- #import <Foundation/Foundation.h>
7
- #import "MAURGeolocationOpenHelper.h"
8
- #import "MAURSessionLocationContract.h"
9
- #import "MAURSessionLocationDAO.h"
10
- #import "MAURLocation.h"
11
- #import "FMDB.h"
12
-
13
- static NSString *const kSessionActiveKey = @"bgloc_session_active";
14
-
15
- @interface MAURSessionLocationDAO ()
16
- - (instancetype)initPrivate;
17
- @end
18
-
19
- @implementation MAURSessionLocationDAO {
20
- FMDatabaseQueue* queue;
21
- MAURGeolocationOpenHelper *helper;
22
- }
23
-
24
- + (instancetype) sharedInstance
25
- {
26
- static MAURSessionLocationDAO *instance = nil;
27
- static dispatch_once_t onceToken;
28
- dispatch_once(&onceToken, ^{
29
- instance = [[self alloc] initPrivate];
30
- });
31
- return instance;
32
- }
33
-
34
- - (instancetype) initPrivate
35
- {
36
- if (self = [super init]) {
37
- helper = [[MAURGeolocationOpenHelper alloc] init];
38
- queue = [helper getWritableDatabase];
39
- }
40
- return self;
41
- }
42
-
43
- - (void) startSession
44
- {
45
- [queue inDatabase:^(FMDatabase *database) {
46
- NSString *sql = [NSString stringWithFormat:@"DELETE FROM %@", @LSC_TABLE_NAME];
47
- [database executeUpdate:sql];
48
- }];
49
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kSessionActiveKey];
50
- [[NSUserDefaults standardUserDefaults] synchronize];
51
- }
52
-
53
- - (void) clearSession
54
- {
55
- [queue inDatabase:^(FMDatabase *database) {
56
- NSString *sql = [NSString stringWithFormat:@"DELETE FROM %@", @LSC_TABLE_NAME];
57
- [database executeUpdate:sql];
58
- }];
59
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kSessionActiveKey];
60
- [[NSUserDefaults standardUserDefaults] synchronize];
61
- }
62
-
63
- - (BOOL) isSessionActive
64
- {
65
- return [[NSUserDefaults standardUserDefaults] boolForKey:kSessionActiveKey];
66
- }
67
-
68
- - (void) persistSessionLocation:(MAURLocation*)location
69
- {
70
- if (![self isSessionActive]) return;
71
- if (!location || !location.time) return;
72
- NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
73
- NSNumber *recordedAt = [NSNumber numberWithDouble:timestamp];
74
-
75
- NSString *sql = @"INSERT INTO " @LSC_TABLE_NAME @" ("
76
- @LSC_COLUMN_NAME_TIME @"," @LSC_COLUMN_NAME_ACCURACY @"," @LSC_COLUMN_NAME_SPEED @","
77
- @LSC_COLUMN_NAME_BEARING @"," @LSC_COLUMN_NAME_ALTITUDE @"," @LSC_COLUMN_NAME_LATITUDE @","
78
- @LSC_COLUMN_NAME_LONGITUDE @"," @LSC_COLUMN_NAME_PROVIDER @"," @LSC_COLUMN_NAME_LOCATION_PROVIDER @","
79
- @LSC_COLUMN_NAME_STATUS @"," @LSC_COLUMN_NAME_RECORDED_AT
80
- @") VALUES (?,?,?,?,?,?,?,?,?,?,?)";
81
-
82
- [queue inDatabase:^(FMDatabase *database) {
83
- [database executeUpdate:sql,
84
- [NSNumber numberWithDouble:[location.time timeIntervalSince1970]],
85
- location.accuracy ?: @0,
86
- location.speed ?: @0,
87
- location.heading ?: @0,
88
- location.altitude ?: @0,
89
- location.latitude ?: @0,
90
- location.longitude ?: @0,
91
- location.provider ?: [NSNull null],
92
- location.locationProvider ? [NSString stringWithFormat:@"%@", location.locationProvider] : [NSNull null],
93
- @(1),
94
- recordedAt
95
- ];
96
- }];
97
- }
98
-
99
- - (NSArray<MAURLocation*>*) getSessionLocations
100
- {
101
- __block NSMutableArray* locations = [[NSMutableArray alloc] init];
102
- NSString *sql = @"SELECT " @LSC_COLUMN_NAME_ID @"," @LSC_COLUMN_NAME_TIME @"," @LSC_COLUMN_NAME_ACCURACY @","
103
- @LSC_COLUMN_NAME_SPEED @"," @LSC_COLUMN_NAME_BEARING @"," @LSC_COLUMN_NAME_ALTITUDE @","
104
- @LSC_COLUMN_NAME_LATITUDE @"," @LSC_COLUMN_NAME_LONGITUDE @"," @LSC_COLUMN_NAME_PROVIDER @","
105
- @LSC_COLUMN_NAME_LOCATION_PROVIDER @"," @LSC_COLUMN_NAME_STATUS @"," @LSC_COLUMN_NAME_RECORDED_AT
106
- @" FROM " @LSC_TABLE_NAME @" ORDER BY " @LSC_COLUMN_NAME_RECORDED_AT;
107
-
108
- [queue inDatabase:^(FMDatabase *database) {
109
- FMResultSet *rs = [database executeQuery:sql];
110
- while ([rs next]) {
111
- MAURLocation *loc = [self convertToLocation:rs];
112
- [locations addObject:loc];
113
- }
114
- [rs close];
115
- }];
116
- return locations;
117
- }
118
-
119
- - (NSInteger) getSessionLocationsCount
120
- {
121
- __block NSInteger count = 0;
122
- NSString *sql = [NSString stringWithFormat:@"SELECT COUNT(*) FROM %@", @LSC_TABLE_NAME];
123
- [queue inDatabase:^(FMDatabase *database) {
124
- FMResultSet *rs = [database executeQuery:sql];
125
- if ([rs next]) {
126
- count = [rs intForColumnIndex:0];
127
- }
128
- [rs close];
129
- }];
130
- return count;
131
- }
132
-
133
- - (MAURLocation*) convertToLocation:(FMResultSet*)rs
134
- {
135
- MAURLocation *location = [[MAURLocation alloc] init];
136
- location.locationId = [NSNumber numberWithLongLong:[rs longLongIntForColumnIndex:0]];
137
- NSTimeInterval timestamp = [rs doubleForColumnIndex:1];
138
- location.time = [NSDate dateWithTimeIntervalSince1970:timestamp];
139
- location.accuracy = [NSNumber numberWithDouble:[rs doubleForColumnIndex:2]];
140
- location.speed = [NSNumber numberWithDouble:[rs doubleForColumnIndex:3]];
141
- location.heading = [NSNumber numberWithDouble:[rs doubleForColumnIndex:4]];
142
- location.altitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:5]];
143
- location.latitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:6]];
144
- location.longitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:7]];
145
- location.provider = [rs stringForColumnIndex:8];
146
- location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:9]];
147
- location.isValid = [rs intForColumnIndex:10] == 1 ? YES : NO;
148
- NSTimeInterval recordedAt = [rs longForColumnIndex:11];
149
- location.recordedAt = [NSDate dateWithTimeIntervalSince1970:recordedAt];
150
- return location;
151
- }
152
-
153
- @end
1
+ //
2
+ // MAURSessionLocationDAO.m
3
+ // BackgroundGeolocation
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import "MAURGeolocationOpenHelper.h"
8
+ #import "MAURSessionLocationContract.h"
9
+ #import "MAURSessionLocationDAO.h"
10
+ #import "MAURLocation.h"
11
+ #import "FMDB.h"
12
+
13
+ static NSString *const kSessionActiveKey = @"bgloc_session_active";
14
+
15
+ @interface MAURSessionLocationDAO ()
16
+ - (instancetype)initPrivate;
17
+ @end
18
+
19
+ @implementation MAURSessionLocationDAO {
20
+ FMDatabaseQueue* queue;
21
+ MAURGeolocationOpenHelper *helper;
22
+ }
23
+
24
+ + (instancetype) sharedInstance
25
+ {
26
+ static MAURSessionLocationDAO *instance = nil;
27
+ static dispatch_once_t onceToken;
28
+ dispatch_once(&onceToken, ^{
29
+ instance = [[self alloc] initPrivate];
30
+ });
31
+ return instance;
32
+ }
33
+
34
+ - (instancetype) initPrivate
35
+ {
36
+ if (self = [super init]) {
37
+ helper = [[MAURGeolocationOpenHelper alloc] init];
38
+ queue = [helper getWritableDatabase];
39
+ }
40
+ return self;
41
+ }
42
+
43
+ - (void) startSession
44
+ {
45
+ [queue inDatabase:^(FMDatabase *database) {
46
+ NSString *sql = [NSString stringWithFormat:@"DELETE FROM %@", @LSC_TABLE_NAME];
47
+ [database executeUpdate:sql];
48
+ }];
49
+ [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kSessionActiveKey];
50
+ [[NSUserDefaults standardUserDefaults] synchronize];
51
+ }
52
+
53
+ - (void) clearSession
54
+ {
55
+ [queue inDatabase:^(FMDatabase *database) {
56
+ NSString *sql = [NSString stringWithFormat:@"DELETE FROM %@", @LSC_TABLE_NAME];
57
+ [database executeUpdate:sql];
58
+ }];
59
+ [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kSessionActiveKey];
60
+ [[NSUserDefaults standardUserDefaults] synchronize];
61
+ }
62
+
63
+ - (BOOL) isSessionActive
64
+ {
65
+ return [[NSUserDefaults standardUserDefaults] boolForKey:kSessionActiveKey];
66
+ }
67
+
68
+ - (void) persistSessionLocation:(MAURLocation*)location
69
+ {
70
+ if (![self isSessionActive]) return;
71
+ if (!location || !location.time) return;
72
+ NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
73
+ NSNumber *recordedAt = [NSNumber numberWithDouble:timestamp];
74
+
75
+ NSString *sql = @"INSERT INTO " @LSC_TABLE_NAME @" ("
76
+ @LSC_COLUMN_NAME_TIME @"," @LSC_COLUMN_NAME_ACCURACY @"," @LSC_COLUMN_NAME_SPEED @","
77
+ @LSC_COLUMN_NAME_BEARING @"," @LSC_COLUMN_NAME_ALTITUDE @"," @LSC_COLUMN_NAME_LATITUDE @","
78
+ @LSC_COLUMN_NAME_LONGITUDE @"," @LSC_COLUMN_NAME_PROVIDER @"," @LSC_COLUMN_NAME_LOCATION_PROVIDER @","
79
+ @LSC_COLUMN_NAME_STATUS @"," @LSC_COLUMN_NAME_RECORDED_AT
80
+ @") VALUES (?,?,?,?,?,?,?,?,?,?,?)";
81
+
82
+ [queue inDatabase:^(FMDatabase *database) {
83
+ [database executeUpdate:sql,
84
+ [NSNumber numberWithDouble:[location.time timeIntervalSince1970]],
85
+ location.accuracy ?: @0,
86
+ location.speed ?: @0,
87
+ location.heading ?: @0,
88
+ location.altitude ?: @0,
89
+ location.latitude ?: @0,
90
+ location.longitude ?: @0,
91
+ location.provider ?: [NSNull null],
92
+ location.locationProvider ? [NSString stringWithFormat:@"%@", location.locationProvider] : [NSNull null],
93
+ @(1),
94
+ recordedAt
95
+ ];
96
+ }];
97
+ }
98
+
99
+ - (NSArray<MAURLocation*>*) getSessionLocations
100
+ {
101
+ __block NSMutableArray* locations = [[NSMutableArray alloc] init];
102
+ NSString *sql = @"SELECT " @LSC_COLUMN_NAME_ID @"," @LSC_COLUMN_NAME_TIME @"," @LSC_COLUMN_NAME_ACCURACY @","
103
+ @LSC_COLUMN_NAME_SPEED @"," @LSC_COLUMN_NAME_BEARING @"," @LSC_COLUMN_NAME_ALTITUDE @","
104
+ @LSC_COLUMN_NAME_LATITUDE @"," @LSC_COLUMN_NAME_LONGITUDE @"," @LSC_COLUMN_NAME_PROVIDER @","
105
+ @LSC_COLUMN_NAME_LOCATION_PROVIDER @"," @LSC_COLUMN_NAME_STATUS @"," @LSC_COLUMN_NAME_RECORDED_AT
106
+ @" FROM " @LSC_TABLE_NAME @" ORDER BY " @LSC_COLUMN_NAME_RECORDED_AT;
107
+
108
+ [queue inDatabase:^(FMDatabase *database) {
109
+ FMResultSet *rs = [database executeQuery:sql];
110
+ while ([rs next]) {
111
+ MAURLocation *loc = [self convertToLocation:rs];
112
+ [locations addObject:loc];
113
+ }
114
+ [rs close];
115
+ }];
116
+ return locations;
117
+ }
118
+
119
+ - (NSInteger) getSessionLocationsCount
120
+ {
121
+ __block NSInteger count = 0;
122
+ NSString *sql = [NSString stringWithFormat:@"SELECT COUNT(*) FROM %@", @LSC_TABLE_NAME];
123
+ [queue inDatabase:^(FMDatabase *database) {
124
+ FMResultSet *rs = [database executeQuery:sql];
125
+ if ([rs next]) {
126
+ count = [rs intForColumnIndex:0];
127
+ }
128
+ [rs close];
129
+ }];
130
+ return count;
131
+ }
132
+
133
+ - (MAURLocation*) convertToLocation:(FMResultSet*)rs
134
+ {
135
+ MAURLocation *location = [[MAURLocation alloc] init];
136
+ location.locationId = [NSNumber numberWithLongLong:[rs longLongIntForColumnIndex:0]];
137
+ NSTimeInterval timestamp = [rs doubleForColumnIndex:1];
138
+ location.time = [NSDate dateWithTimeIntervalSince1970:timestamp];
139
+ location.accuracy = [NSNumber numberWithDouble:[rs doubleForColumnIndex:2]];
140
+ location.speed = [NSNumber numberWithDouble:[rs doubleForColumnIndex:3]];
141
+ location.heading = [NSNumber numberWithDouble:[rs doubleForColumnIndex:4]];
142
+ location.altitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:5]];
143
+ location.latitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:6]];
144
+ location.longitude = [NSNumber numberWithDouble:[rs doubleForColumnIndex:7]];
145
+ location.provider = [rs stringForColumnIndex:8];
146
+ location.locationProvider = [NSNumber numberWithInt:[rs intForColumnIndex:9]];
147
+ location.isValid = [rs intForColumnIndex:10] == 1 ? YES : NO;
148
+ NSTimeInterval recordedAt = [rs longForColumnIndex:11];
149
+ location.recordedAt = [NSDate dateWithTimeIntervalSince1970:recordedAt];
150
+ return location;
151
+ }
152
+
153
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@josuelmm/cordova-background-geolocation",
3
- "version": "4.5.2",
3
+ "version": "4.5.5",
4
4
  "description": "Cordova Background Geolocation (fork actualizado)",
5
5
  "main": "./www/BackgroundGeolocation.js",
6
6
  "types": "./www/BackgroundGeolocation.d.ts",
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova-background-geolocation"
5
- version="4.5.2">
5
+ version="4.5.5">
6
6
  <name>cordova-background-geolocation</name>
7
7
  <description>Cordova Background Geolocation Plugin</description>
8
8
  <license>Apache-2.0</license>
@@ -557,7 +557,7 @@ export interface ConfigureOptions {
557
557
  stationaryPollFast?: number;
558
558
 
559
559
  /**
560
- * v4.5.2 — Activity-recognition confidence threshold (0-100). Transitions below this
560
+ * v4.5.4 — Activity-recognition confidence threshold (0-100). Transitions below this
561
561
  * confidence are ignored, preventing jittery STILL/ACTIVE flips that cause spurious
562
562
  * GPS start/stop bursts. Only used by `ACTIVITY_PROVIDER`.
563
563
  *
@@ -567,12 +567,12 @@ export interface ConfigureOptions {
567
567
  * Platform: Android, iOS
568
568
  * Provider: ACTIVITY
569
569
  * @default 50
570
- * @since 4.5.2
570
+ * @since 4.5.4
571
571
  */
572
572
  activityConfidenceThreshold?: number;
573
573
 
574
574
  /**
575
- * v4.5.2 — Maximum accepted horizontal accuracy in meters. Fixes whose reported
575
+ * v4.5.4 — Maximum accepted horizontal accuracy in meters. Fixes whose reported
576
576
  * accuracy is worse than this value are dropped before reaching the JS layer
577
577
  * (and before being persisted / posted / synced).
578
578
  *
@@ -581,7 +581,7 @@ export interface ConfigureOptions {
581
581
  *
582
582
  * Platform: Android, iOS
583
583
  * Provider: all
584
- * @since 4.5.2
584
+ * @since 4.5.4
585
585
  */
586
586
  maxAcceptedAccuracy?: number;
587
587