@josuelmm/capacitor-background-geolocation 1.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.
Files changed (207) hide show
  1. package/JosuelmmCapacitorBackgroundGeolocation.podspec +34 -0
  2. package/LICENSE +17 -0
  3. package/NOTICE.md +32 -0
  4. package/Package.swift +45 -0
  5. package/README.md +402 -0
  6. package/android/build.gradle +79 -0
  7. package/android/proguard-rules.pro +1 -0
  8. package/android/src/main/AndroidManifest.xml +83 -0
  9. package/android/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
  10. package/android/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
  11. package/android/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
  12. package/android/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
  13. package/android/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
  14. package/android/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
  15. package/android/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
  16. package/android/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
  17. package/android/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
  18. package/android/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
  19. package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/BackgroundGeolocationPlugin.java +898 -0
  20. package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/ConfigMapper.java +303 -0
  21. package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/HeadlessTaskRegistry.java +34 -0
  22. package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/JsEvaluatorTaskRunner.java +63 -0
  23. package/android/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +699 -0
  24. package/android/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +103 -0
  25. package/android/src/main/java/com/marianhello/bgloc/Config.java +1155 -0
  26. package/android/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
  27. package/android/src/main/java/com/marianhello/bgloc/HttpPostService.java +362 -0
  28. package/android/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
  29. package/android/src/main/java/com/marianhello/bgloc/PluginDelegate.java +45 -0
  30. package/android/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
  31. package/android/src/main/java/com/marianhello/bgloc/PostLocationTask.java +238 -0
  32. package/android/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
  33. package/android/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
  34. package/android/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
  35. package/android/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
  36. package/android/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +1088 -0
  37. package/android/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
  38. package/android/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
  39. package/android/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
  40. package/android/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
  41. package/android/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +27 -0
  42. package/android/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
  43. package/android/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +71 -0
  44. package/android/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
  45. package/android/src/main/java/com/marianhello/bgloc/data/SessionLocationDAO.java +18 -0
  46. package/android/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +406 -0
  47. package/android/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
  48. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +94 -0
  49. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +227 -0
  50. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +122 -0
  51. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +550 -0
  52. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +189 -0
  53. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionContract.java +74 -0
  54. package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionLocationDAO.java +169 -0
  55. package/android/src/main/java/com/marianhello/bgloc/driving/DrivingEventsDetector.java +265 -0
  56. package/android/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
  57. package/android/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
  58. package/android/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
  59. package/android/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
  60. package/android/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
  61. package/android/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
  62. package/android/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
  63. package/android/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
  64. package/android/src/main/java/com/marianhello/bgloc/http/UrlTemplateResolver.java +115 -0
  65. package/android/src/main/java/com/marianhello/bgloc/oem/BatteryOemHelper.java +214 -0
  66. package/android/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +218 -0
  67. package/android/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +385 -0
  68. package/android/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +685 -0
  69. package/android/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
  70. package/android/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
  71. package/android/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
  72. package/android/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +175 -0
  73. package/android/src/main/java/com/marianhello/bgloc/sensor/SensorFusionDetector.java +199 -0
  74. package/android/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
  75. package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +1531 -0
  76. package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
  77. package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
  78. package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
  79. package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +156 -0
  80. package/android/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
  81. package/android/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
  82. package/android/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
  83. package/android/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +311 -0
  84. package/android/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
  85. package/android/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +301 -0
  86. package/android/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
  87. package/android/src/main/java/com/marianhello/logging/DBLogReader.java +208 -0
  88. package/android/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
  89. package/android/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
  90. package/android/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
  91. package/android/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
  92. package/android/src/main/java/com/marianhello/utils/Convert.java +56 -0
  93. package/android/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
  94. package/android/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
  95. package/android/src/main/java/org/apache/commons/io/Charsets.java +153 -0
  96. package/android/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
  97. package/android/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
  98. package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
  99. package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
  100. package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
  101. package/android/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
  102. package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  103. package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  104. package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  105. package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  106. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  107. package/android/src/main/res/values/strings.xml +15 -0
  108. package/android/src/main/res/xml/authenticator.xml +7 -0
  109. package/android/src/main/res/xml/syncadapter.xml +9 -0
  110. package/dist/esm/definitions.d.ts +1052 -0
  111. package/dist/esm/definitions.js +142 -0
  112. package/dist/esm/definitions.js.map +1 -0
  113. package/dist/esm/index.d.ts +8 -0
  114. package/dist/esm/index.js +23 -0
  115. package/dist/esm/index.js.map +1 -0
  116. package/dist/esm/web.d.ts +92 -0
  117. package/dist/esm/web.js +242 -0
  118. package/dist/esm/web.js.map +1 -0
  119. package/dist/plugin.cjs.js +415 -0
  120. package/dist/plugin.cjs.js.map +1 -0
  121. package/dist/plugin.js +418 -0
  122. package/dist/plugin.js.map +1 -0
  123. package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin-Bridging-Header.h +18 -0
  124. package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.m +52 -0
  125. package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.swift +750 -0
  126. package/ios/Tests/BackgroundGeolocationPluginTests/BackgroundGeolocationPluginTests.swift +12 -0
  127. package/ios/common/BackgroundGeolocation/CocoaLumberjack.h +1945 -0
  128. package/ios/common/BackgroundGeolocation/CocoaLumberjack.m +5255 -0
  129. package/ios/common/BackgroundGeolocation/FMDB.h +2357 -0
  130. package/ios/common/BackgroundGeolocation/FMDB.m +2672 -0
  131. package/ios/common/BackgroundGeolocation/FMDBLogger.h +42 -0
  132. package/ios/common/BackgroundGeolocation/FMDBLogger.m +264 -0
  133. package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.h +41 -0
  134. package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.m +68 -0
  135. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager+Internal.h +33 -0
  136. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.h +178 -0
  137. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.m +1025 -0
  138. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.h +103 -0
  139. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.m +238 -0
  140. package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequestDefines.h +163 -0
  141. package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.h +39 -0
  142. package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.m +37 -0
  143. package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.h +51 -0
  144. package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.m +53 -0
  145. package/ios/common/BackgroundGeolocation/MAURActivity.h +23 -0
  146. package/ios/common/BackgroundGeolocation/MAURActivity.m +52 -0
  147. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.h +18 -0
  148. package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +340 -0
  149. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +88 -0
  150. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +1193 -0
  151. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +46 -0
  152. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +283 -0
  153. package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
  154. package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
  155. package/ios/common/BackgroundGeolocation/MAURConfig.h +99 -0
  156. package/ios/common/BackgroundGeolocation/MAURConfig.m +636 -0
  157. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +53 -0
  158. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +54 -0
  159. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
  160. package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +550 -0
  161. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
  162. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +124 -0
  163. package/ios/common/BackgroundGeolocation/MAURLocation.h +73 -0
  164. package/ios/common/BackgroundGeolocation/MAURLocation.m +392 -0
  165. package/ios/common/BackgroundGeolocation/MAURLocationContract.h +38 -0
  166. package/ios/common/BackgroundGeolocation/MAURLocationContract.m +39 -0
  167. package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
  168. package/ios/common/BackgroundGeolocation/MAURLocationManager.m +305 -0
  169. package/ios/common/BackgroundGeolocation/MAURLogReader.h +26 -0
  170. package/ios/common/BackgroundGeolocation/MAURLogReader.m +122 -0
  171. package/ios/common/BackgroundGeolocation/MAURLogging.h +19 -0
  172. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +53 -0
  173. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +367 -0
  174. package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
  175. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
  176. package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +138 -0
  177. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
  178. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +335 -0
  179. package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
  180. package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
  181. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +52 -0
  182. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +520 -0
  183. package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
  184. package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
  185. package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.h +41 -0
  186. package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.m +137 -0
  187. package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.h +29 -0
  188. package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.m +31 -0
  189. package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.h +25 -0
  190. package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.m +153 -0
  191. package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
  192. package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
  193. package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.h +31 -0
  194. package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.m +107 -0
  195. package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
  196. package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
  197. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/README.md +170 -0
  198. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.h +55 -0
  199. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.m +47 -0
  200. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlDataManipulationCommand.h +27 -0
  201. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.h +250 -0
  202. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.m +259 -0
  203. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.h +360 -0
  204. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.m +427 -0
  205. package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlStatement.h +37 -0
  206. package/ios/common/BackgroundGeolocation/module.modulemap +16 -0
  207. package/package.json +82 -0
@@ -0,0 +1,42 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "CocoaLumberjack.h"
3
+
4
+ @class FMDatabase;
5
+
6
+
7
+ @interface FMDBLogger : DDAbstractDatabaseLogger <DDLogger>
8
+ {
9
+ @private
10
+ NSString *logDirectory;
11
+ NSMutableArray *pendingLogEntries;
12
+
13
+ FMDatabase *database;
14
+ }
15
+
16
+ /**
17
+ * Initializes an instance set to save it's sqlite file to the given directory.
18
+ * If the directory doesn't already exist, it is automatically created.
19
+ **/
20
+ - (id)initWithLogDirectory:(NSString *)logDirectory;
21
+
22
+ //
23
+ // This class inherits from DDAbstractDatabaseLogger.
24
+ //
25
+ // So there are a bunch of options such as:
26
+ //
27
+ // @property (assign, readwrite) NSUInteger saveThreshold;
28
+ // @property (assign, readwrite) NSTimeInterval saveInterval;
29
+ //
30
+ // @property (assign, readwrite) NSTimeInterval maxAge;
31
+ // @property (assign, readwrite) NSTimeInterval deleteInterval;
32
+ // @property (assign, readwrite) BOOL deleteOnEverySave;
33
+ //
34
+ // And methods such as:
35
+ //
36
+ // - (void)savePendingLogEntries;
37
+ // - (void)deleteOldLogEntries;
38
+ //
39
+ // These options and methods are documented extensively in DDAbstractDatabaseLogger.h
40
+ //
41
+
42
+ @end
@@ -0,0 +1,264 @@
1
+ #import "FMDBLogger.h"
2
+ #import "FMDB.h"
3
+
4
+
5
+ @interface FMDBLogger ()
6
+ - (void)validateLogDirectory;
7
+ - (void)openDatabase;
8
+ @end
9
+
10
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11
+ #pragma mark -
12
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13
+
14
+ @interface FMDBLogEntry : NSObject {
15
+ @public
16
+ NSNumber * context;
17
+ NSNumber * level;
18
+ NSString * message;
19
+ NSDate * timestamp;
20
+ }
21
+
22
+ - (id)initWithLogMessage:(DDLogMessage *)logMessage;
23
+
24
+ @end
25
+
26
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27
+ #pragma mark -
28
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29
+
30
+ @implementation FMDBLogEntry
31
+
32
+ - (id)initWithLogMessage:(DDLogMessage *)logMessage
33
+ {
34
+ if ((self = [super init]))
35
+ {
36
+ context = @(logMessage->_context);
37
+ level = @(logMessage->_flag);
38
+ message = logMessage->_message;
39
+ timestamp = logMessage->_timestamp;
40
+ }
41
+ return self;
42
+ }
43
+
44
+
45
+ @end
46
+
47
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48
+ #pragma mark -
49
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50
+
51
+ @implementation FMDBLogger
52
+
53
+ - (id)initWithLogDirectory:(NSString *)aLogDirectory
54
+ {
55
+ if ((self = [super init]))
56
+ {
57
+ logDirectory = [aLogDirectory copy];
58
+
59
+ pendingLogEntries = [[NSMutableArray alloc] initWithCapacity:_saveThreshold];
60
+
61
+ [self validateLogDirectory];
62
+ [self openDatabase];
63
+ }
64
+
65
+ return self;
66
+ }
67
+
68
+
69
+ - (void)validateLogDirectory
70
+ {
71
+ // Validate log directory exists or create the directory.
72
+
73
+ BOOL isDirectory;
74
+ if ([[NSFileManager defaultManager] fileExistsAtPath:logDirectory isDirectory:&isDirectory])
75
+ {
76
+ if (!isDirectory)
77
+ {
78
+ NSLog(@"%@: %@ - logDirectory(%@) is a file!", [self class], THIS_METHOD, logDirectory);
79
+
80
+ logDirectory = nil;
81
+ }
82
+ }
83
+ else
84
+ {
85
+ NSError *error = nil;
86
+
87
+ BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:logDirectory
88
+ withIntermediateDirectories:YES
89
+ attributes:nil
90
+ error:&error];
91
+ if (!result)
92
+ {
93
+ NSLog(@"%@: %@ - Unable to create logDirectory(%@) due to error: %@",
94
+ [self class], THIS_METHOD, logDirectory, error);
95
+
96
+ logDirectory = nil;
97
+ }
98
+ }
99
+ }
100
+
101
+ - (void)openDatabase
102
+ {
103
+ if (logDirectory == nil)
104
+ {
105
+ return;
106
+ }
107
+
108
+ NSString *path = [logDirectory stringByAppendingPathComponent:@"log.sqlite"];
109
+
110
+ database = [[FMDatabase alloc] initWithPath:path];
111
+
112
+ if (![database open])
113
+ {
114
+ NSLog(@"%@: Failed opening database!", [self class]);
115
+
116
+ database = nil;
117
+
118
+ return;
119
+ }
120
+
121
+ NSString *cmd1 = @"CREATE TABLE IF NOT EXISTS logs (context integer, "
122
+ "level integer, "
123
+ "message text, "
124
+ "timestamp double)";
125
+ [database executeUpdate:cmd1];
126
+ if ([database hadError])
127
+ {
128
+ NSLog(@"%@: Error creating table: code(%d): %@",
129
+ [self class], [database lastErrorCode], [database lastErrorMessage]);
130
+
131
+ database = nil;
132
+ }
133
+
134
+ NSString *cmd2 = @"CREATE INDEX IF NOT EXISTS timestamp ON logs (timestamp)";
135
+
136
+ [database executeUpdate:cmd2];
137
+ if ([database hadError])
138
+ {
139
+ NSLog(@"%@: Error creating index: code(%d): %@",
140
+ [self class], [database lastErrorCode], [database lastErrorMessage]);
141
+
142
+ database = nil;
143
+ }
144
+
145
+ [database setShouldCacheStatements:YES];
146
+ }
147
+
148
+ #pragma mark AbstractDatabaseLogger Overrides
149
+
150
+ - (BOOL)db_log:(DDLogMessage *)logMessage
151
+ {
152
+ // You may be wondering, how come we don't just do the insert here and be done with it?
153
+ // Is the buffering really needed?
154
+ //
155
+ // From the SQLite FAQ:
156
+ //
157
+ // (19) INSERT is really slow - I can only do few dozen INSERTs per second
158
+ //
159
+ // Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer.
160
+ // But it will only do a few dozen transactions per second. Transaction speed is limited by the rotational
161
+ // speed of your disk drive. A transaction normally requires two complete rotations of the disk platter, which
162
+ // on a 7200RPM disk drive limits you to about 60 transactions per second.
163
+ //
164
+ // Transaction speed is limited by disk drive speed because (by default) SQLite actually waits until the data
165
+ // really is safely stored on the disk surface before the transaction is complete. That way, if you suddenly
166
+ // lose power or if your OS crashes, your data is still safe. For details, read about atomic commit in SQLite.
167
+ //
168
+ // By default, each INSERT statement is its own transaction. But if you surround multiple INSERT statements
169
+ // with BEGIN...COMMIT then all the inserts are grouped into a single transaction. The time needed to commit
170
+ // the transaction is amortized over all the enclosed insert statements and so the time per insert statement
171
+ // is greatly reduced.
172
+
173
+ FMDBLogEntry *logEntry = [[FMDBLogEntry alloc] initWithLogMessage:logMessage];
174
+
175
+ [pendingLogEntries addObject:logEntry];
176
+
177
+ // Return YES if an item was added to the buffer.
178
+ // Return NO if the logMessage was ignored.
179
+
180
+ return YES;
181
+ }
182
+
183
+ - (void)db_save
184
+ {
185
+ if ([pendingLogEntries count] == 0)
186
+ {
187
+ // Nothing to save.
188
+ // The superclass won't likely call us if this is the case, but we're being cautious.
189
+ return;
190
+ }
191
+
192
+ BOOL saveOnlyTransaction = ![database inTransaction];
193
+
194
+ if (saveOnlyTransaction)
195
+ {
196
+ [database beginTransaction];
197
+ }
198
+
199
+ NSString *cmd = @"INSERT INTO logs (context, level, message, timestamp) VALUES (?, ?, ?, ?)";
200
+
201
+ for (FMDBLogEntry *logEntry in pendingLogEntries)
202
+ {
203
+ [database executeUpdate:cmd, logEntry->context,
204
+ logEntry->level,
205
+ logEntry->message,
206
+ logEntry->timestamp];
207
+ }
208
+
209
+ [pendingLogEntries removeAllObjects];
210
+
211
+ if (saveOnlyTransaction)
212
+ {
213
+ [database commit];
214
+
215
+ if ([database hadError])
216
+ {
217
+ NSLog(@"%@: Error inserting log entries: code(%d): %@",
218
+ [self class], [database lastErrorCode], [database lastErrorMessage]);
219
+ }
220
+ }
221
+ }
222
+
223
+ - (void)db_delete
224
+ {
225
+ if (_maxAge <= 0.0)
226
+ {
227
+ // Deleting old log entries is disabled.
228
+ // The superclass won't likely call us if this is the case, but we're being cautious.
229
+ return;
230
+ }
231
+
232
+ BOOL deleteOnlyTransaction = ![database inTransaction];
233
+
234
+ NSDate *maxDate = [NSDate dateWithTimeIntervalSinceNow:(-1.0 * _maxAge)];
235
+
236
+ [database executeUpdate:@"DELETE FROM logs WHERE timestamp < ?", maxDate];
237
+
238
+ if (deleteOnlyTransaction)
239
+ {
240
+ if ([database hadError])
241
+ {
242
+ NSLog(@"%@: Error deleting log entries: code(%d): %@",
243
+ [self class], [database lastErrorCode], [database lastErrorMessage]);
244
+ }
245
+ }
246
+ }
247
+
248
+ - (void)db_saveAndDelete
249
+ {
250
+ [database beginTransaction];
251
+
252
+ [self db_delete];
253
+ [self db_save];
254
+
255
+ [database commit];
256
+
257
+ if ([database hadError])
258
+ {
259
+ NSLog(@"%@: Error: code(%d): %@",
260
+ [self class], [database lastErrorCode], [database lastErrorMessage]);
261
+ }
262
+ }
263
+
264
+ @end
@@ -0,0 +1,41 @@
1
+ //
2
+ // INTUHeadingRequest.h
3
+ //
4
+ // Copyright (c) 2014-2017 Intuit Inc.
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining
7
+ // a copy of this software and associated documentation files (the
8
+ // "Software"), to deal in the Software without restriction, including
9
+ // without limitation the rights to use, copy, modify, merge, publish,
10
+ // distribute, sublicense, and/or sell copies of the Software, and to
11
+ // permit persons to whom the Software is furnished to do so, subject to
12
+ // the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be
15
+ // included in all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ //
25
+
26
+ #import "INTULocationRequestDefines.h"
27
+
28
+ NS_ASSUME_NONNULL_BEGIN
29
+
30
+ @interface INTUHeadingRequest : NSObject
31
+
32
+ /** The request ID for this heading request (set during initialization). */
33
+ @property (nonatomic, readonly) INTUHeadingRequestID requestID;
34
+ /** Whether this is a recurring heading request (all heading requests are assumed to be for now). */
35
+ @property (nonatomic, readonly) BOOL isRecurring;
36
+ /** The block to execute when the heading request completes. */
37
+ @property (nonatomic, copy, nullable) INTUHeadingRequestBlock block;
38
+
39
+ @end
40
+
41
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,68 @@
1
+ //
2
+ // INTUHeadingRequest.m
3
+ //
4
+ // Copyright (c) 2014-2017 Intuit Inc.
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining
7
+ // a copy of this software and associated documentation files (the
8
+ // "Software"), to deal in the Software without restriction, including
9
+ // without limitation the rights to use, copy, modify, merge, publish,
10
+ // distribute, sublicense, and/or sell copies of the Software, and to
11
+ // permit persons to whom the Software is furnished to do so, subject to
12
+ // the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be
15
+ // included in all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ //
25
+
26
+ #import "INTUHeadingRequest.h"
27
+ #import "INTURequestIDGenerator.h"
28
+
29
+ @implementation INTUHeadingRequest
30
+
31
+ /**
32
+ Designated initializer. Initializes and returns a newly allocated heading request.
33
+ */
34
+ - (instancetype)init
35
+ {
36
+ if (self = [super init]) {
37
+ _requestID = [INTURequestIDGenerator getUniqueRequestID];
38
+ _isRecurring = YES;
39
+ }
40
+ return self;
41
+ }
42
+
43
+ /**
44
+ Two heading requests are considered equal if their request IDs match.
45
+ */
46
+ - (BOOL)isEqual:(id)object
47
+ {
48
+ if (object == self) {
49
+ return YES;
50
+ }
51
+ if (!object || ![object isKindOfClass:[self class]]) {
52
+ return NO;
53
+ }
54
+ if (((INTUHeadingRequest *)object).requestID == self.requestID) {
55
+ return YES;
56
+ }
57
+ return NO;
58
+ }
59
+
60
+ /**
61
+ Return a hash based on the string representation of the request ID.
62
+ */
63
+ - (NSUInteger)hash
64
+ {
65
+ return [[NSString stringWithFormat:@"%ld", (long)self.requestID] hash];
66
+ }
67
+
68
+ @end
@@ -0,0 +1,33 @@
1
+ //
2
+ // INTULocationManager+Internal.h
3
+ //
4
+ // Copyright (c) 2014-2017 Intuit Inc.
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining
7
+ // a copy of this software and associated documentation files (the
8
+ // "Software"), to deal in the Software without restriction, including
9
+ // without limitation the rights to use, copy, modify, merge, publish,
10
+ // distribute, sublicense, and/or sell copies of the Software, and to
11
+ // permit persons to whom the Software is furnished to do so, subject to
12
+ // the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be
15
+ // included in all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ //
25
+
26
+ #import "INTULocationManager.h"
27
+
28
+ /**
29
+ A category that exposes the internal (private) methods of INTULocationManager.
30
+ */
31
+ @interface INTULocationManager (Internal) <CLLocationManagerDelegate>
32
+
33
+ @end
@@ -0,0 +1,178 @@
1
+ //
2
+ // INTULocationManager.h
3
+ //
4
+ // Copyright (c) 2014-2017 Intuit Inc.
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining
7
+ // a copy of this software and associated documentation files (the
8
+ // "Software"), to deal in the Software without restriction, including
9
+ // without limitation the rights to use, copy, modify, merge, publish,
10
+ // distribute, sublicense, and/or sell copies of the Software, and to
11
+ // permit persons to whom the Software is furnished to do so, subject to
12
+ // the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be
15
+ // included in all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ //
25
+
26
+ #import "INTULocationRequestDefines.h"
27
+
28
+ //! Project version number for INTULocationManager.
29
+ FOUNDATION_EXPORT double INTULocationManagerVersionNumber;
30
+
31
+ //! Project version string for INTULocationManager.
32
+ FOUNDATION_EXPORT const unsigned char INTULocationManagerVersionString[];
33
+
34
+
35
+ NS_ASSUME_NONNULL_BEGIN
36
+
37
+ /**
38
+ An abstraction around CLLocationManager that provides a block-based asynchronous API for obtaining the device's location.
39
+ INTULocationManager automatically starts and stops system location services as needed to minimize battery drain.
40
+ */
41
+ @interface INTULocationManager : NSObject
42
+
43
+ /** Returns the current state of location services for this app, based on the system settings and user authorization status. */
44
+ + (INTULocationServicesState)locationServicesState;
45
+
46
+ /** Returns the current state of heading services for this device. */
47
+ + (INTUHeadingServicesState)headingServicesState;
48
+
49
+ /** Returns the singleton instance of this class. */
50
+ + (instancetype)sharedInstance;
51
+
52
+ #pragma mark Location Requests
53
+
54
+ /**
55
+ Asynchronously requests the current location of the device using location services.
56
+
57
+ @param desiredAccuracy The accuracy level desired (refers to the accuracy and recency of the location).
58
+ @param timeout The maximum amount of time (in seconds) to wait for a location with the desired accuracy before completing. If
59
+ this value is 0.0, no timeout will be set (will wait indefinitely for success, unless request is force completed or canceled).
60
+ @param block The block to execute upon success, failure, or timeout.
61
+
62
+ @return The location request ID, which can be used to force early completion or cancel the request while it is in progress.
63
+ */
64
+ - (INTULocationRequestID)requestLocationWithDesiredAccuracy:(INTULocationAccuracy)desiredAccuracy
65
+ timeout:(NSTimeInterval)timeout
66
+ block:(INTULocationRequestBlock)block;
67
+
68
+ /**
69
+ Asynchronously requests the current location of the device using location services, optionally delaying the timeout countdown until the user has
70
+ responded to the dialog requesting permission for this app to access location services.
71
+
72
+ @param desiredAccuracy The accuracy level desired (refers to the accuracy and recency of the location).
73
+ @param timeout The maximum amount of time (in seconds) to wait for a location with the desired accuracy before completing. If
74
+ this value is 0.0, no timeout will be set (will wait indefinitely for success, unless request is force completed or canceled).
75
+ @param delayUntilAuthorized A flag specifying whether the timeout should only take effect after the user responds to the system prompt requesting
76
+ permission for this app to access location services. If YES, the timeout countdown will not begin until after the
77
+ app receives location services permissions. If NO, the timeout countdown begins immediately when calling this method.
78
+ @param block The block to execute upon success, failure, or timeout.
79
+
80
+ @return The location request ID, which can be used to force early completion or cancel the request while it is in progress.
81
+ */
82
+ - (INTULocationRequestID)requestLocationWithDesiredAccuracy:(INTULocationAccuracy)desiredAccuracy
83
+ timeout:(NSTimeInterval)timeout
84
+ delayUntilAuthorized:(BOOL)delayUntilAuthorized
85
+ block:(INTULocationRequestBlock)block;
86
+
87
+ /**
88
+ Creates a subscription for location updates that will execute the block once per update indefinitely (until canceled), regardless of the accuracy of each location.
89
+ This method instructs location services to use the highest accuracy available (which also requires the most power).
90
+ If an error occurs, the block will execute with a status other than INTULocationStatusSuccess, and the subscription will be canceled automatically.
91
+
92
+ @param block The block to execute every time an updated location is available.
93
+ The status will be INTULocationStatusSuccess unless an error occurred; it will never be INTULocationStatusTimedOut.
94
+
95
+ @return The location request ID, which can be used to cancel the subscription of location updates to this block.
96
+ */
97
+ - (INTULocationRequestID)subscribeToLocationUpdatesWithBlock:(INTULocationRequestBlock)block;
98
+
99
+ /**
100
+ Creates a subscription for location updates that will execute the block once per update indefinitely (until canceled), regardless of the accuracy of each location.
101
+ The specified desired accuracy is passed along to location services, and controls how much power is used, with higher accuracies using more power.
102
+ If an error occurs, the block will execute with a status other than INTULocationStatusSuccess, and the subscription will be canceled automatically.
103
+
104
+ @param desiredAccuracy The accuracy level desired, which controls how much power is used by the device's location services.
105
+ @param block The block to execute every time an updated location is available. Note that this block runs for every update, regardless of
106
+ whether the achievedAccuracy is at least the desiredAccuracy.
107
+ The status will be INTULocationStatusSuccess unless an error occurred; it will never be INTULocationStatusTimedOut.
108
+
109
+ @return The location request ID, which can be used to cancel the subscription of location updates to this block.
110
+ */
111
+ - (INTULocationRequestID)subscribeToLocationUpdatesWithDesiredAccuracy:(INTULocationAccuracy)desiredAccuracy
112
+ block:(INTULocationRequestBlock)block;
113
+
114
+ /**
115
+ Creates a subscription for significant location changes that will execute the block once per change indefinitely (until canceled).
116
+ If an error occurs, the block will execute with a status other than INTULocationStatusSuccess, and the subscription will be canceled automatically.
117
+
118
+ @param block The block to execute every time an updated location is available.
119
+ The status will be INTULocationStatusSuccess unless an error occurred; it will never be INTULocationStatusTimedOut.
120
+
121
+ @return The location request ID, which can be used to cancel the subscription of significant location changes to this block.
122
+ */
123
+ - (INTULocationRequestID)subscribeToSignificantLocationChangesWithBlock:(INTULocationRequestBlock)block;
124
+
125
+ /** Immediately forces completion of the location request with the given requestID (if it exists), and executes the original request block with the results.
126
+ For one-time location requests, this is effectively a manual timeout, and will result in the request completing with status INTULocationStatusTimedOut.
127
+ If the requestID corresponds to a subscription, then the subscription will simply be canceled. */
128
+ - (void)forceCompleteLocationRequest:(INTULocationRequestID)requestID;
129
+
130
+ /** Immediately cancels the location request (or subscription) with the given requestID (if it exists), without executing the original request block. */
131
+ - (void)cancelLocationRequest:(INTULocationRequestID)requestID;
132
+
133
+ #pragma mark Heading Requests
134
+
135
+ /**
136
+ Creates a subscription for heading updates that will execute the block once per update indefinitely (until canceled), assuming the heading update exceeded the heading filter threshold.
137
+ If an error occurs, the block will execute with a status other than INTUHeadingStatusSuccess, and the subscription will be canceled automatically.
138
+
139
+ @param block The block to execute every time an updated heading is available. The status will be INTUHeadingStatusSuccess unless an error occurred.
140
+
141
+ @return The heading request ID, which can be used to cancel the subscription of heading updates to this block.
142
+ */
143
+ - (INTUHeadingRequestID)subscribeToHeadingUpdatesWithBlock:(INTUHeadingRequestBlock)block;
144
+
145
+ /** Immediately cancels the heading subscription request with the given requestID (if it exists), without executing the original request block. */
146
+ - (void)cancelHeadingRequest:(INTUHeadingRequestID)requestID;
147
+
148
+ #pragma mark - Additions
149
+
150
+ /** It is possible to force enable background location fetch even if your set any kind of Authorizations */
151
+ - (void)setBackgroundLocationUpdate:(BOOL) enabled;
152
+
153
+ /**
154
+ Sets a Boolean indicating whether the status bar changes its appearance when location services
155
+ are used in the background.
156
+
157
+ This property affects only apps that received always authorization. When such an app moves to the background,
158
+ the system uses this property to determine whether to change the status bar appearance to indicate that
159
+ location services are in use. Displaying a modified status bar gives the user a quick way to return to your app.
160
+ The default value of this property is false.
161
+
162
+ For apps with when-in-use authorization, the system always changes the status bar appearance when
163
+ the app uses location services in the background.
164
+
165
+ @param shows Boolean indicating whether the status bar changes its appearance when location services are used in the background.
166
+ */
167
+ - (void)setShowsBackgroundLocationIndicator:(BOOL) shows;
168
+
169
+ /**
170
+ Sets a Boolean value indicating whether the location manager object may pause location updates.
171
+
172
+ @param pauses Boolean value indicating whether the location manager object may pause location updates.
173
+ */
174
+ - (void)setPausesLocationUpdatesAutomatically:(BOOL) pauses;
175
+
176
+ @end
177
+
178
+ NS_ASSUME_NONNULL_END