@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.
- package/JosuelmmCapacitorBackgroundGeolocation.podspec +34 -0
- package/LICENSE +17 -0
- package/NOTICE.md +32 -0
- package/Package.swift +45 -0
- package/README.md +402 -0
- package/android/build.gradle +79 -0
- package/android/proguard-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +83 -0
- package/android/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
- package/android/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
- package/android/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
- package/android/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
- package/android/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
- package/android/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/BackgroundGeolocationPlugin.java +898 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/ConfigMapper.java +303 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/HeadlessTaskRegistry.java +34 -0
- package/android/src/main/java/com/josuelmm/capacitor/backgroundgeolocation/JsEvaluatorTaskRunner.java +63 -0
- package/android/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +699 -0
- package/android/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +103 -0
- package/android/src/main/java/com/marianhello/bgloc/Config.java +1155 -0
- package/android/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
- package/android/src/main/java/com/marianhello/bgloc/HttpPostService.java +362 -0
- package/android/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
- package/android/src/main/java/com/marianhello/bgloc/PluginDelegate.java +45 -0
- package/android/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
- package/android/src/main/java/com/marianhello/bgloc/PostLocationTask.java +238 -0
- package/android/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
- package/android/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
- package/android/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
- package/android/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
- package/android/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +1088 -0
- package/android/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +211 -0
- package/android/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
- package/android/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
- package/android/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +27 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +71 -0
- package/android/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
- package/android/src/main/java/com/marianhello/bgloc/data/SessionLocationDAO.java +18 -0
- package/android/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +406 -0
- package/android/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +94 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +227 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +122 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +550 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +189 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionContract.java +74 -0
- package/android/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteSessionLocationDAO.java +169 -0
- package/android/src/main/java/com/marianhello/bgloc/driving/DrivingEventsDetector.java +265 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
- package/android/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
- package/android/src/main/java/com/marianhello/bgloc/http/UrlTemplateResolver.java +115 -0
- package/android/src/main/java/com/marianhello/bgloc/oem/BatteryOemHelper.java +214 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +218 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +385 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +685 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
- package/android/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +175 -0
- package/android/src/main/java/com/marianhello/bgloc/sensor/SensorFusionDetector.java +199 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +1531 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
- package/android/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +156 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +311 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +301 -0
- package/android/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
- package/android/src/main/java/com/marianhello/logging/DBLogReader.java +208 -0
- package/android/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
- package/android/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
- package/android/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
- package/android/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
- package/android/src/main/java/com/marianhello/utils/Convert.java +56 -0
- package/android/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
- package/android/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
- package/android/src/main/java/org/apache/commons/io/Charsets.java +153 -0
- package/android/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
- package/android/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
- package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
- package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
- package/android/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
- package/android/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/values/strings.xml +15 -0
- package/android/src/main/res/xml/authenticator.xml +7 -0
- package/android/src/main/res/xml/syncadapter.xml +9 -0
- package/dist/esm/definitions.d.ts +1052 -0
- package/dist/esm/definitions.js +142 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +92 -0
- package/dist/esm/web.js +242 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +415 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +418 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin-Bridging-Header.h +18 -0
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.m +52 -0
- package/ios/Sources/BackgroundGeolocationPlugin/BackgroundGeolocationPlugin.swift +750 -0
- package/ios/Tests/BackgroundGeolocationPluginTests/BackgroundGeolocationPluginTests.swift +12 -0
- package/ios/common/BackgroundGeolocation/CocoaLumberjack.h +1945 -0
- package/ios/common/BackgroundGeolocation/CocoaLumberjack.m +5255 -0
- package/ios/common/BackgroundGeolocation/FMDB.h +2357 -0
- package/ios/common/BackgroundGeolocation/FMDB.m +2672 -0
- package/ios/common/BackgroundGeolocation/FMDBLogger.h +42 -0
- package/ios/common/BackgroundGeolocation/FMDBLogger.m +264 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.h +41 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTUHeadingRequest.m +68 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager+Internal.h +33 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.h +178 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationManager.m +1025 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.h +103 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequest.m +238 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTULocationRequestDefines.h +163 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.h +39 -0
- package/ios/common/BackgroundGeolocation/INTULocationManager/INTURequestIDGenerator.m +37 -0
- package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.h +51 -0
- package/ios/common/BackgroundGeolocation/MAURAbstractLocationProvider.m +53 -0
- package/ios/common/BackgroundGeolocation/MAURActivity.h +23 -0
- package/ios/common/BackgroundGeolocation/MAURActivity.m +52 -0
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURActivityLocationProvider.m +340 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +88 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +1193 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +46 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +283 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.h +99 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.m +636 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +54 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +550 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +124 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.h +73 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.m +392 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.h +38 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.m +39 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.m +305 -0
- package/ios/common/BackgroundGeolocation/MAURLogReader.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURLogReader.m +122 -0
- package/ios/common/BackgroundGeolocation/MAURLogging.h +19 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +367 -0
- package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +138 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +335 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +520 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
- package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.h +41 -0
- package/ios/common/BackgroundGeolocation/MAURSensorFusionDetector.m +137 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.h +29 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationContract.m +31 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURSessionLocationDAO.m +153 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
- package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.h +31 -0
- package/ios/common/BackgroundGeolocation/MAURUrlTemplateResolver.m +107 -0
- package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
- package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/README.md +170 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.h +55 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/ext/NSString+ZIMString.m +47 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlDataManipulationCommand.h +27 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.h +250 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlExpression.m +259 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.h +360 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlSelectStatement.m +427 -0
- package/ios/common/BackgroundGeolocation/SQLQueryBuilder/sql/ZIMSqlStatement.h +37 -0
- package/ios/common/BackgroundGeolocation/module.modulemap +16 -0
- package/package.json +82 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MAURConfigurationContract.m
|
|
3
|
+
// BackgroundGeolocation
|
|
4
|
+
//
|
|
5
|
+
// Created by Marian Hello on 01/12/2017.
|
|
6
|
+
// Copyright © 2017 mauron85. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "MAURSQLiteHelper.h"
|
|
11
|
+
#import "MAURConfigurationContract.h"
|
|
12
|
+
|
|
13
|
+
@implementation MAURConfigurationContract
|
|
14
|
+
|
|
15
|
+
+ (NSString*) createTableSQL
|
|
16
|
+
{
|
|
17
|
+
NSArray *columns = @[
|
|
18
|
+
@{ @"name": @CC_COLUMN_NAME_ID, @"type": [SQLPrimaryKeyAutoIncColumnType sqlColumnWithType: kInteger]},
|
|
19
|
+
@{ @"name": @CC_COLUMN_NAME_RADIUS, @"type": [SQLColumnType sqlColumnWithType: kReal]},
|
|
20
|
+
@{ @"name": @CC_COLUMN_NAME_DISTANCE_FILTER, @"type": [SQLColumnType sqlColumnWithType: kReal]},
|
|
21
|
+
@{ @"name": @CC_COLUMN_NAME_DESIRED_ACCURACY, @"type": [SQLColumnType sqlColumnWithType: kReal]},
|
|
22
|
+
@{ @"name": @CC_COLUMN_NAME_DEBUG, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
23
|
+
@{ @"name": @CC_COLUMN_NAME_ACTIVITY_TYPE, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
24
|
+
@{ @"name": @CC_COLUMN_NAME_NOTIF_TITLE, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
25
|
+
@{ @"name": @CC_COLUMN_NAME_NOTIF_TEXT, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
26
|
+
@{ @"name": @CC_COLUMN_NAME_NOTIF_ICON_LARGE, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
27
|
+
@{ @"name": @CC_COLUMN_NAME_NOTIF_ICON_SMALL, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
28
|
+
@{ @"name": @CC_COLUMN_NAME_NOTIF_COLOR, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
29
|
+
@{ @"name": @CC_COLUMN_NAME_STOP_TERMINATE, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
30
|
+
@{ @"name": @CC_COLUMN_NAME_START_BOOT, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
31
|
+
@{ @"name": @CC_COLUMN_NAME_START_FOREGROUND, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
32
|
+
@{ @"name": @CC_COLUMN_NAME_STOP_ON_STILL, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
33
|
+
@{ @"name": @CC_COLUMN_NAME_LOCATION_PROVIDER, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
34
|
+
@{ @"name": @CC_COLUMN_NAME_INTERVAL, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
35
|
+
@{ @"name": @CC_COLUMN_NAME_FASTEST_INTERVAL, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
36
|
+
@{ @"name": @CC_COLUMN_NAME_ACTIVITIES_INTERVAL, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
37
|
+
@{ @"name": @CC_COLUMN_NAME_URL, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
38
|
+
@{ @"name": @CC_COLUMN_NAME_SYNC_URL, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
39
|
+
@{ @"name": @CC_COLUMN_NAME_SYNC_THRESHOLD, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
40
|
+
@{ @"name": @CC_COLUMN_NAME_SYNC_ENABLED, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
41
|
+
@{ @"name": @CC_COLUMN_NAME_HEADERS, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
42
|
+
@{ @"name": @CC_COLUMN_NAME_SAVE_BATTERY, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
43
|
+
@{ @"name": @CC_COLUMN_NAME_MAX_LOCATIONS, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
44
|
+
@{ @"name": @CC_COLUMN_NAME_PAUSE_LOCATION_UPDATES, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
45
|
+
@{ @"name": @CC_COLUMN_NAME_TEMPLATE, @"type": [SQLColumnType sqlColumnWithType: kText]},
|
|
46
|
+
@{ @"name": @CC_COLUMN_NAME_LAST_UPDATED_AT, @"type": [SQLColumnType sqlColumnWithType: kInteger]},
|
|
47
|
+
// v4.5: full Config JSON blob
|
|
48
|
+
@{ @"name": @CC_COLUMN_NAME_CONFIG_JSON, @"type": [SQLColumnType sqlColumnWithType: kText]}
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
return [MAURSQLiteHelper createTableSqlStatement:@CC_TABLE_NAME columns:columns];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MAURDistanceFilterLocationProvider.h
|
|
3
|
+
// BackgroundGeolocation
|
|
4
|
+
//
|
|
5
|
+
// Created by Marian Hello on 14/09/2016.
|
|
6
|
+
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef MAURDistanceFilterLocationProvider_h
|
|
10
|
+
#define MAURDistanceFilterLocationProvider_h
|
|
11
|
+
|
|
12
|
+
#import <CoreLocation/CoreLocation.h>
|
|
13
|
+
#import "MAURAbstractLocationProvider.h"
|
|
14
|
+
#import "MAURConfig.h"
|
|
15
|
+
|
|
16
|
+
@interface MAURDistanceFilterLocationProvider : MAURAbstractLocationProvider<MAURLocationProvider>
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
#endif /* MAURDistanceFilterLocationProvider_h */
|
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MAURDistanceFilterLocationProvider.m
|
|
3
|
+
// BackgroundGeolocation
|
|
4
|
+
//
|
|
5
|
+
// Created by Marian Hello on 14/09/2016.
|
|
6
|
+
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "MAURDistanceFilterLocationProvider.h"
|
|
10
|
+
#import "MAURLogging.h"
|
|
11
|
+
|
|
12
|
+
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
|
|
13
|
+
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
|
|
14
|
+
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
|
|
15
|
+
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
|
|
16
|
+
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
|
|
17
|
+
|
|
18
|
+
#define LOCATION_DENIED "User denied use of location services."
|
|
19
|
+
#define LOCATION_RESTRICTED "Application's use of location services is restricted."
|
|
20
|
+
#define LOCATION_NOT_DETERMINED "User undecided on application's use of location services."
|
|
21
|
+
|
|
22
|
+
static NSString * const TAG = @"DistanceFilterLocationProvider";
|
|
23
|
+
static NSString * const Domain = @"com.marianhello";
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
enum {
|
|
27
|
+
maxLocationWaitTimeInSeconds = 15,
|
|
28
|
+
maxLocationAgeInSeconds = 30
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
@interface MAURDistanceFilterLocationProvider () <CLLocationManagerDelegate>
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
@implementation MAURDistanceFilterLocationProvider {
|
|
35
|
+
BOOL isUpdatingLocation;
|
|
36
|
+
BOOL isAcquiringStationaryLocation;
|
|
37
|
+
BOOL isAcquiringSpeed;
|
|
38
|
+
BOOL isStarted;
|
|
39
|
+
|
|
40
|
+
CLCircularRegion *stationaryRegion;
|
|
41
|
+
NSDate *stationarySince;
|
|
42
|
+
|
|
43
|
+
MAUROperationalMode operationMode;
|
|
44
|
+
NSDate *aquireStartTime;
|
|
45
|
+
|
|
46
|
+
CLLocationManager *locationManager;
|
|
47
|
+
|
|
48
|
+
// configurable options
|
|
49
|
+
MAURConfig *_config;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
- (instancetype) init
|
|
54
|
+
{
|
|
55
|
+
self = [super init];
|
|
56
|
+
|
|
57
|
+
if (self) {
|
|
58
|
+
isUpdatingLocation = NO;
|
|
59
|
+
isAcquiringStationaryLocation = NO;
|
|
60
|
+
isAcquiringSpeed = NO;
|
|
61
|
+
stationaryRegion = nil;
|
|
62
|
+
isStarted = NO;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return self;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- (void) onCreate {
|
|
69
|
+
locationManager = [[CLLocationManager alloc] init];
|
|
70
|
+
|
|
71
|
+
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
|
|
72
|
+
DDLogDebug(@"%@ iOS9 detected", TAG);
|
|
73
|
+
locationManager.allowsBackgroundLocationUpdates = YES;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
locationManager.delegate = self;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* configure provider
|
|
81
|
+
* @param {Config} configuration
|
|
82
|
+
* @param {NSError} optional error
|
|
83
|
+
*/
|
|
84
|
+
- (BOOL) onConfigure:(MAURConfig*)config error:(NSError * __autoreleasing *)outError
|
|
85
|
+
{
|
|
86
|
+
DDLogVerbose(@"%@ configure", TAG);
|
|
87
|
+
_config = config;
|
|
88
|
+
|
|
89
|
+
locationManager.pausesLocationUpdatesAutomatically = [_config pauseLocationUpdates];
|
|
90
|
+
// v3.4 Phase 3: showsBackgroundLocationIndicator (iOS 11+).
|
|
91
|
+
if (@available(iOS 11.0, *)) {
|
|
92
|
+
if ([_config hasShowsBackgroundLocationIndicator]) {
|
|
93
|
+
locationManager.showsBackgroundLocationIndicator = [_config showsBackgroundLocationIndicator];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
locationManager.activityType = [_config decodeActivityType];
|
|
97
|
+
locationManager.distanceFilter = _config.distanceFilter.integerValue; // meters
|
|
98
|
+
locationManager.desiredAccuracy = [_config decodeDesiredAccuracy];
|
|
99
|
+
|
|
100
|
+
return YES;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Turn on background geolocation
|
|
105
|
+
*/
|
|
106
|
+
- (BOOL) onStart:(NSError * __autoreleasing *)outError
|
|
107
|
+
{
|
|
108
|
+
DDLogInfo(@"%@ will start", TAG);
|
|
109
|
+
|
|
110
|
+
NSUInteger authStatus;
|
|
111
|
+
|
|
112
|
+
if ([CLLocationManager respondsToSelector:@selector(authorizationStatus)]) { // iOS 4.2+
|
|
113
|
+
authStatus = [CLLocationManager authorizationStatus];
|
|
114
|
+
|
|
115
|
+
if (authStatus == kCLAuthorizationStatusDenied) {
|
|
116
|
+
if (outError != NULL) {
|
|
117
|
+
NSDictionary *errorDictionary = @{
|
|
118
|
+
NSLocalizedDescriptionKey: NSLocalizedString(@LOCATION_DENIED, nil)
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
*outError = [NSError errorWithDomain:Domain code:MAURBGPermissionDenied userInfo:errorDictionary];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return NO;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (authStatus == kCLAuthorizationStatusRestricted) {
|
|
128
|
+
if (outError != NULL) {
|
|
129
|
+
NSDictionary *errorDictionary = @{
|
|
130
|
+
NSLocalizedDescriptionKey: NSLocalizedString(@LOCATION_RESTRICTED, nil)
|
|
131
|
+
};
|
|
132
|
+
*outError = [NSError errorWithDomain:Domain code:MAURBGPermissionDenied userInfo:errorDictionary];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return NO;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#ifdef __IPHONE_8_0
|
|
139
|
+
// we do startUpdatingLocation even though we might not get permissions granted
|
|
140
|
+
// we can stop later on when recieved callback on user denial
|
|
141
|
+
// it's neccessary to start call startUpdatingLocation in iOS < 8.0 to show user prompt!
|
|
142
|
+
|
|
143
|
+
if (authStatus == kCLAuthorizationStatusNotDetermined) {
|
|
144
|
+
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { //iOS 8.0+
|
|
145
|
+
DDLogVerbose(@"%@ requestAlwaysAuthorization", TAG);
|
|
146
|
+
[locationManager requestAlwaysAuthorization];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
#endif
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
[self switchMode:MAURForegroundMode];
|
|
153
|
+
|
|
154
|
+
isStarted = YES;
|
|
155
|
+
|
|
156
|
+
return YES;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Turn it off
|
|
161
|
+
*/
|
|
162
|
+
- (BOOL) onStop:(NSError * __autoreleasing *)outError
|
|
163
|
+
{
|
|
164
|
+
DDLogInfo(@"%@ stop", TAG);
|
|
165
|
+
|
|
166
|
+
[self stopUpdatingLocation];
|
|
167
|
+
[self stopMonitoringSignificantLocationChanges];
|
|
168
|
+
[self stopMonitoringForRegion];
|
|
169
|
+
|
|
170
|
+
isStarted = NO;
|
|
171
|
+
|
|
172
|
+
return YES;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
- (void) onSwitchMode:(MAUROperationalMode)mode
|
|
176
|
+
{
|
|
177
|
+
[self switchMode:mode];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* toggle between foreground and background operation mode
|
|
182
|
+
*/
|
|
183
|
+
- (void) switchMode:(MAUROperationalMode)mode
|
|
184
|
+
{
|
|
185
|
+
DDLogInfo(@"%@ switchMode %lu", TAG, (unsigned long)mode);
|
|
186
|
+
|
|
187
|
+
operationMode = mode;
|
|
188
|
+
|
|
189
|
+
if (operationMode == MAURForegroundMode || !_config.saveBatteryOnBackground) {
|
|
190
|
+
isAcquiringSpeed = YES;
|
|
191
|
+
isAcquiringStationaryLocation = NO;
|
|
192
|
+
[self stopMonitoringForRegion];
|
|
193
|
+
[self stopMonitoringSignificantLocationChanges];
|
|
194
|
+
} else if (operationMode == MAURBackgroundMode) {
|
|
195
|
+
isAcquiringSpeed = NO;
|
|
196
|
+
isAcquiringStationaryLocation = YES;
|
|
197
|
+
[self startMonitoringSignificantLocationChanges];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
aquireStartTime = [NSDate date];
|
|
201
|
+
|
|
202
|
+
// Crank up the GPS power temporarily to get a good fix on our current location
|
|
203
|
+
[self stopUpdatingLocation];
|
|
204
|
+
locationManager.distanceFilter = kCLDistanceFilterNone;
|
|
205
|
+
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
|
|
206
|
+
[self startUpdatingLocation];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
|
|
210
|
+
{
|
|
211
|
+
DDLogDebug(@"%@ didUpdateLocations (operationMode: %lu)", TAG, (unsigned long)operationMode);
|
|
212
|
+
|
|
213
|
+
MAUROperationalMode actAsInMode = operationMode;
|
|
214
|
+
|
|
215
|
+
if (actAsInMode == MAURBackgroundMode) {
|
|
216
|
+
if ([_config saveBatteryOnBackground] == NO) actAsInMode = MAURForegroundMode;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (actAsInMode == MAURForegroundMode) {
|
|
220
|
+
if (!isUpdatingLocation) [self startUpdatingLocation];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (actAsInMode == MAURBackgroundMode) {
|
|
224
|
+
if (!isAcquiringStationaryLocation && !stationaryRegion) {
|
|
225
|
+
// Perhaps our GPS signal was interupted, re-acquire a stationaryLocation now.
|
|
226
|
+
[self switchMode:operationMode];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
MAURLocation *bestLocation = nil;
|
|
232
|
+
for (CLLocation *location in locations) {
|
|
233
|
+
MAURLocation *bgloc = [MAURLocation fromCLLocation:location];
|
|
234
|
+
|
|
235
|
+
// test the age of the location measurement to determine if the measurement is cached
|
|
236
|
+
// in most cases you will not want to rely on cached measurements
|
|
237
|
+
DDLogDebug(@"Location age %f", [bgloc locationAge]);
|
|
238
|
+
if ([bgloc locationAge] > maxLocationAgeInSeconds || ![bgloc hasAccuracy] || ![bgloc hasTime]) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (bestLocation == nil) {
|
|
243
|
+
bestLocation = bgloc;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if ([bgloc isBetterLocation:bestLocation]) {
|
|
248
|
+
DDLogInfo(@"Better location found: %@", bgloc);
|
|
249
|
+
bestLocation = bgloc;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (bestLocation == nil) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// test the measurement to see if it is more accurate than the previous measurement
|
|
258
|
+
if (isAcquiringStationaryLocation) {
|
|
259
|
+
DDLogDebug(@"%@ acquiring stationary location, accuracy: %@", TAG, bestLocation.accuracy);
|
|
260
|
+
if ([_config isDebugging]) {
|
|
261
|
+
AudioServicesPlaySystemSound (acquiringLocationSound);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if ([bestLocation.accuracy doubleValue] <= [_config.desiredAccuracy doubleValue]) {
|
|
265
|
+
DDLogDebug(@"%@ found most accurate stationary before timeout", TAG);
|
|
266
|
+
} else if (-[aquireStartTime timeIntervalSinceNow] < maxLocationWaitTimeInSeconds) {
|
|
267
|
+
// we still have time to aquire better location
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
isAcquiringStationaryLocation = NO;
|
|
272
|
+
[self stopUpdatingLocation]; //saving power while monitoring region
|
|
273
|
+
|
|
274
|
+
MAURLocation *stationaryLocation = [bestLocation copy];
|
|
275
|
+
stationaryLocation.radius = _config.stationaryRadius;
|
|
276
|
+
stationaryLocation.time = stationarySince;
|
|
277
|
+
[self startMonitoringStationaryRegion:stationaryLocation];
|
|
278
|
+
// fire onStationary @event for Javascript.
|
|
279
|
+
[super.delegate onStationaryChanged:stationaryLocation];
|
|
280
|
+
} else if (isAcquiringSpeed) {
|
|
281
|
+
if ([_config isDebugging]) {
|
|
282
|
+
AudioServicesPlaySystemSound (acquiringLocationSound);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if ([bestLocation.accuracy doubleValue] <= [_config.desiredAccuracy doubleValue]) {
|
|
286
|
+
DDLogDebug(@"%@ found most accurate location before timeout", TAG);
|
|
287
|
+
} else if (-[aquireStartTime timeIntervalSinceNow] < maxLocationWaitTimeInSeconds) {
|
|
288
|
+
// we still have time to aquire better location
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if ([_config isDebugging]) {
|
|
293
|
+
[self notify:@"Aggressive monitoring engaged"];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// We should have a good sample for speed now, power down our GPS as configured by user.
|
|
297
|
+
isAcquiringSpeed = NO;
|
|
298
|
+
locationManager.desiredAccuracy = _config.desiredAccuracy.integerValue;
|
|
299
|
+
locationManager.distanceFilter = [self calculateDistanceFilter:[bestLocation.speed floatValue]];
|
|
300
|
+
[self startUpdatingLocation];
|
|
301
|
+
|
|
302
|
+
} else if (actAsInMode == MAURForegroundMode) {
|
|
303
|
+
// Adjust distanceFilter incrementally based upon current speed
|
|
304
|
+
float newDistanceFilter = [self calculateDistanceFilter:[bestLocation.speed floatValue]];
|
|
305
|
+
if (newDistanceFilter != locationManager.distanceFilter) {
|
|
306
|
+
DDLogInfo(@"%@ updated distanceFilter, new: %f, old: %f", TAG, newDistanceFilter, locationManager.distanceFilter);
|
|
307
|
+
locationManager.distanceFilter = newDistanceFilter;
|
|
308
|
+
[self startUpdatingLocation];
|
|
309
|
+
}
|
|
310
|
+
} else if ([self locationIsBeyondStationaryRegion:bestLocation]) {
|
|
311
|
+
if ([_config isDebugging]) {
|
|
312
|
+
[self notify:@"Manual stationary exit-detection"];
|
|
313
|
+
}
|
|
314
|
+
[self switchMode:operationMode];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
[super.delegate onLocationChanged:bestLocation];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Called when user exits their stationary radius (ie: they walked ~50m away from their last recorded location.
|
|
322
|
+
*
|
|
323
|
+
*/
|
|
324
|
+
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLCircularRegion *)region
|
|
325
|
+
{
|
|
326
|
+
CLLocationDistance radius = [region radius];
|
|
327
|
+
CLLocationCoordinate2D coordinate = [region center];
|
|
328
|
+
|
|
329
|
+
DDLogDebug(@"%@ didExitRegion {%f,%f,%f}", TAG, coordinate.latitude, coordinate.longitude, radius);
|
|
330
|
+
if ([_config isDebugging]) {
|
|
331
|
+
AudioServicesPlaySystemSound (exitRegionSound);
|
|
332
|
+
[self notify:@"Exit stationary region"];
|
|
333
|
+
}
|
|
334
|
+
[self switchMode:operationMode];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
- (void) locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager
|
|
338
|
+
{
|
|
339
|
+
DDLogDebug(@"%@ location updates paused", TAG);
|
|
340
|
+
if ([_config isDebugging]) {
|
|
341
|
+
[self notify:@"Location updates paused"];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
- (void) locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
|
|
346
|
+
{
|
|
347
|
+
DDLogDebug(@"%@ location updates resumed", TAG);
|
|
348
|
+
if ([_config isDebugging]) {
|
|
349
|
+
[self notify:@"Location updates resumed b"];
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
|
|
354
|
+
{
|
|
355
|
+
DDLogError(@"%@ didFailWithError: %@", TAG, error);
|
|
356
|
+
if ([_config isDebugging]) {
|
|
357
|
+
AudioServicesPlaySystemSound (locationErrorSound);
|
|
358
|
+
[self notify:[NSString stringWithFormat:@"Location error: %@", error.localizedDescription]];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
switch(error.code) {
|
|
362
|
+
case kCLErrorLocationUnknown:
|
|
363
|
+
case kCLErrorNetwork:
|
|
364
|
+
case kCLErrorRegionMonitoringDenied:
|
|
365
|
+
case kCLErrorRegionMonitoringSetupDelayed:
|
|
366
|
+
case kCLErrorRegionMonitoringResponseDelayed:
|
|
367
|
+
case kCLErrorGeocodeFoundNoResult:
|
|
368
|
+
case kCLErrorGeocodeFoundPartialResult:
|
|
369
|
+
case kCLErrorGeocodeCanceled:
|
|
370
|
+
break;
|
|
371
|
+
case kCLErrorDenied:
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(onError:)]) {
|
|
376
|
+
NSDictionary *errorDictionary = @{
|
|
377
|
+
NSUnderlyingErrorKey : error
|
|
378
|
+
};
|
|
379
|
+
NSError *outError = [NSError errorWithDomain:Domain code:MAURBGServiceError userInfo:errorDictionary];
|
|
380
|
+
|
|
381
|
+
[self.delegate onError:outError];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// v3.4 Phase 3: iOS 14+ delegate callback. Replaces the legacy `didChangeAuthorizationStatus:`
|
|
386
|
+
// (which is deprecated in iOS 14 but still delivered). On iOS 14+ this is the canonical entry
|
|
387
|
+
// point and exposes accuracyAuthorization (Precise vs Reduced).
|
|
388
|
+
- (void) locationManagerDidChangeAuthorization:(CLLocationManager *)manager API_AVAILABLE(ios(14.0))
|
|
389
|
+
{
|
|
390
|
+
CLAuthorizationStatus status = manager.authorizationStatus;
|
|
391
|
+
DDLogInfo(@"LocationManager didChangeAuthorization (iOS 14+) status=%d accuracy=%ld",
|
|
392
|
+
(int)status, (long)manager.accuracyAuthorization);
|
|
393
|
+
[self handleAuthorizationStatusChange:status];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
|
|
397
|
+
{
|
|
398
|
+
// On iOS 14+ the system also delivers `locationManagerDidChangeAuthorization:`; ignore this
|
|
399
|
+
// legacy callback there to avoid double-notifying delegates.
|
|
400
|
+
if (@available(iOS 14.0, *)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
DDLogInfo(@"LocationManager didChangeAuthorizationStatus (legacy) %u", status);
|
|
404
|
+
[self handleAuthorizationStatusChange:status];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
- (void) handleAuthorizationStatusChange:(CLAuthorizationStatus)status
|
|
408
|
+
{
|
|
409
|
+
if ([_config isDebugging]) {
|
|
410
|
+
[self notify:[NSString stringWithFormat:@"Authorization status changed %u", status]];
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
switch(status) {
|
|
414
|
+
case kCLAuthorizationStatusRestricted:
|
|
415
|
+
case kCLAuthorizationStatusDenied:
|
|
416
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(onAuthorizationChanged:)]) {
|
|
417
|
+
[self.delegate onAuthorizationChanged:MAURLocationAuthorizationDenied];
|
|
418
|
+
}
|
|
419
|
+
break;
|
|
420
|
+
case kCLAuthorizationStatusAuthorizedAlways:
|
|
421
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(onAuthorizationChanged:)]) {
|
|
422
|
+
[self.delegate onAuthorizationChanged:MAURLocationAuthorizationAlways];
|
|
423
|
+
}
|
|
424
|
+
break;
|
|
425
|
+
case kCLAuthorizationStatusAuthorizedWhenInUse:
|
|
426
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(onAuthorizationChanged:)]) {
|
|
427
|
+
[self.delegate onAuthorizationChanged:MAURLocationAuthorizationForeground];
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
430
|
+
default:
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
- (void) stopUpdatingLocation
|
|
436
|
+
{
|
|
437
|
+
if (isUpdatingLocation) {
|
|
438
|
+
[locationManager stopUpdatingLocation];
|
|
439
|
+
isUpdatingLocation = NO;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
- (void) startUpdatingLocation
|
|
444
|
+
{
|
|
445
|
+
if (!isUpdatingLocation) {
|
|
446
|
+
[locationManager startUpdatingLocation];
|
|
447
|
+
isUpdatingLocation = YES;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
- (void) onTerminate
|
|
452
|
+
{
|
|
453
|
+
if (isStarted && !_config.stopOnTerminate) {
|
|
454
|
+
[locationManager startMonitoringSignificantLocationChanges];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
- (void) startMonitoringSignificantLocationChanges
|
|
459
|
+
{
|
|
460
|
+
[locationManager startMonitoringSignificantLocationChanges];
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
- (void) stopMonitoringSignificantLocationChanges
|
|
464
|
+
{
|
|
465
|
+
[locationManager stopMonitoringSignificantLocationChanges];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Creates a new circle around user and region-monitors it for exit
|
|
470
|
+
*/
|
|
471
|
+
- (void) startMonitoringStationaryRegion:(MAURLocation*)location {
|
|
472
|
+
CLLocationCoordinate2D coord = [location coordinate];
|
|
473
|
+
DDLogDebug(@"%@ startMonitoringStationaryRegion {%f,%f,%@}", TAG, coord.latitude, coord.longitude, _config.stationaryRadius);
|
|
474
|
+
|
|
475
|
+
if ([_config isDebugging]) {
|
|
476
|
+
AudioServicesPlaySystemSound (acquiredLocationSound);
|
|
477
|
+
[self notify:[NSString stringWithFormat:@"Monitoring region {%f,%f,%@}", location.coordinate.latitude, location.coordinate.longitude, _config.stationaryRadius]];
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
[self stopMonitoringForRegion];
|
|
481
|
+
stationaryRegion = [[CLCircularRegion alloc] initWithCenter: coord radius:_config.stationaryRadius.integerValue identifier:@"DistanceFilterProvider stationary region"];
|
|
482
|
+
stationaryRegion.notifyOnExit = YES;
|
|
483
|
+
[locationManager startMonitoringForRegion:stationaryRegion];
|
|
484
|
+
stationarySince = [NSDate date];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
- (void) stopMonitoringForRegion
|
|
488
|
+
{
|
|
489
|
+
if (stationaryRegion != nil) {
|
|
490
|
+
[locationManager stopMonitoringForRegion:stationaryRegion];
|
|
491
|
+
stationaryRegion = nil;
|
|
492
|
+
stationarySince = nil;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10. Clamped at 1km max.
|
|
498
|
+
*/
|
|
499
|
+
- (float) calculateDistanceFilter:(float)speed
|
|
500
|
+
{
|
|
501
|
+
float newDistanceFilter = _config.distanceFilter.integerValue;
|
|
502
|
+
if (speed < 100) {
|
|
503
|
+
// (rounded-speed-to-nearest-5) / 2)^2
|
|
504
|
+
// eg 5.2 becomes (5/2)^2
|
|
505
|
+
newDistanceFilter = pow((5.0 * floorf(fabsf(speed) / 5.0 + 0.5f)), 2) + _config.distanceFilter.integerValue;
|
|
506
|
+
}
|
|
507
|
+
return (newDistanceFilter < 1000) ? newDistanceFilter : 1000;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Manual stationary location his-testing. This seems to help stationary-exit detection in some places where the automatic geo-fencing doesn't
|
|
512
|
+
*/
|
|
513
|
+
- (BOOL) locationIsBeyondStationaryRegion:(MAURLocation*)location
|
|
514
|
+
{
|
|
515
|
+
CLLocationCoordinate2D regionCenter = [stationaryRegion center];
|
|
516
|
+
BOOL containsCoordinate = [stationaryRegion containsCoordinate:[location coordinate]];
|
|
517
|
+
|
|
518
|
+
DDLogVerbose(@"%@ location {%@,%@} region {%f,%f,%f} contains: %d",
|
|
519
|
+
TAG,
|
|
520
|
+
location.latitude, location.longitude, regionCenter.latitude, regionCenter.longitude,
|
|
521
|
+
[stationaryRegion radius], containsCoordinate);
|
|
522
|
+
|
|
523
|
+
return !containsCoordinate;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
- (void) notify:(NSString*)message
|
|
527
|
+
{
|
|
528
|
+
[super notify:message];
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
- (void) onDestroy {
|
|
532
|
+
DDLogInfo(@"Destroying %@ ", TAG);
|
|
533
|
+
[self onStop:nil];
|
|
534
|
+
|
|
535
|
+
// v4.5.2: release our delegate slot so a CLLocationManager retained by the
|
|
536
|
+
// OS (e.g. while a stationary region monitor is still alive briefly after
|
|
537
|
+
// stop) cannot deliver callbacks to a destroyed provider.
|
|
538
|
+
if (locationManager != nil && locationManager.delegate == self) {
|
|
539
|
+
locationManager.delegate = nil;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
- (void) dealloc
|
|
544
|
+
{
|
|
545
|
+
if (locationManager != nil && locationManager.delegate == self) {
|
|
546
|
+
locationManager.delegate = nil;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
@end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MAURGeolocationOpenHelper.h
|
|
3
|
+
// BackgroundGeolocation
|
|
4
|
+
//
|
|
5
|
+
// Created by Marian Hello on 27/06/16.
|
|
6
|
+
// Copyright © 2016 mauron85. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef MAURGeolocationOpenHelper_h
|
|
10
|
+
#define MAURGeolocationOpenHelper_h
|
|
11
|
+
|
|
12
|
+
#import "MAURSQLiteOpenHelper.h"
|
|
13
|
+
|
|
14
|
+
@interface MAURGeolocationOpenHelper : MAURSQLiteOpenHelper
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
#endif /* MAURGeolocationOpenHelper_h */
|