@josuelmm/cordova-background-geolocation 2.3.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.
- package/.npmignore +23 -0
- package/CHANGELOG.md +787 -0
- package/CONTRIBUTORS.md +15 -0
- package/HISTORY.md +734 -0
- package/LICENSE +191 -0
- package/README.md +125 -0
- package/RELEASE.MD +5 -0
- package/android/CDVBackgroundGeolocation/src/main/AndroidManifest.xml +23 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/HandlerWrapper.java +18 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JavaScriptInterface.java +22 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsEvaluator.java +133 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/JsFunctionCallFormatter.java +37 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/WebViewWrapper.java +71 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/CallJavaResultInterface.java +8 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/HandlerWrapperInterface.java +5 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsCallback.java +10 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/JsEvaluatorInterface.java +18 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/evgenii/jsevaluator/interfaces/WebViewWrapperInterface.java +14 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +148 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/PluginRegistry.java +25 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/headless/JsEvaluatorTaskRunner.java +53 -0
- package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +603 -0
- package/android/CDVBackgroundGeolocation/src/main/res/values/strings.xml +4 -0
- package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +208 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +45 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +570 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +76 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +437 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +95 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +159 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +161 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +247 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +200 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +457 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +96 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +225 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +46 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +14 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +50 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +17 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +92 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +107 -0
- package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +5 -0
- package/android/common/src/main/AndroidManifest.xml +72 -0
- package/android/common/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java +523 -0
- package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +59 -0
- package/android/common/src/main/java/com/marianhello/bgloc/Config.java +652 -0
- package/android/common/src/main/java/com/marianhello/bgloc/ConnectivityListener.java +5 -0
- package/android/common/src/main/java/com/marianhello/bgloc/HttpPostService.java +224 -0
- package/android/common/src/main/java/com/marianhello/bgloc/LocationManager.java +138 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PluginDelegate.java +19 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PluginException.java +38 -0
- package/android/common/src/main/java/com/marianhello/bgloc/PostLocationTask.java +188 -0
- package/android/common/src/main/java/com/marianhello/bgloc/ResourceResolver.java +55 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/AbstractLocationTemplate.java +69 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ArrayListLocationTemplate.java +88 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundActivity.java +108 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +994 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigurationDAO.java +13 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/DAOFactory.java +17 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/HashMapLocationTemplate.java +82 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationDAO.java +22 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplate.java +12 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +65 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTransform.java +19 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/provider/ContentProviderLocationDAO.java +395 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/provider/LocationContentProvider.java +321 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +76 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +160 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +112 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +506 -0
- package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +151 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/AbstractTaskRunner.java +15 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/ActivityTask.java +48 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/JsCallback.java +10 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/LocationTask.java +60 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/StationaryTask.java +25 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/Task.java +8 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunner.java +5 -0
- package/android/common/src/main/java/com/marianhello/bgloc/headless/TaskRunnerFactory.java +8 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/AbstractLocationProvider.java +171 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ActivityRecognitionLocationProvider.java +282 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +610 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProvider.java +32 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/LocationProviderFactory.java +47 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/ProviderDelegate.java +12 -0
- package/android/common/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java +145 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationService.java +16 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +749 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfo.java +6 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceInfoImpl.java +41 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceIntentBuilder.java +203 -0
- package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +130 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/AccountHelper.java +39 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/Authenticator.java +68 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/AuthenticatorService.java +28 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +278 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/NotificationHelper.java +148 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java +249 -0
- package/android/common/src/main/java/com/marianhello/bgloc/sync/SyncService.java +68 -0
- package/android/common/src/main/java/com/marianhello/logging/DBLogReader.java +203 -0
- package/android/common/src/main/java/com/marianhello/logging/LogEntry.java +99 -0
- package/android/common/src/main/java/com/marianhello/logging/LoggerManager.java +70 -0
- package/android/common/src/main/java/com/marianhello/logging/UncaughtExceptionLogger.java +36 -0
- package/android/common/src/main/java/com/marianhello/utils/CloneHelper.java +22 -0
- package/android/common/src/main/java/com/marianhello/utils/Convert.java +56 -0
- package/android/common/src/main/java/com/marianhello/utils/TextUtils.java +72 -0
- package/android/common/src/main/java/com/marianhello/utils/ToneGenerator.java +68 -0
- package/android/common/src/main/java/org/apache/commons/io/Charsets.java +153 -0
- package/android/common/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +344 -0
- package/android/common/src/main/java/org/chromium/content/browser/ThreadUtils.java +134 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlExpression.java +398 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlSelectStatement.java +671 -0
- package/android/common/src/main/java/ru/andremoniy/sqlbuilder/SqlStatement.java +29 -0
- package/android/common/src/main/java/ru/andremoniy/utils/TextUtils.java +61 -0
- package/android/common/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/common/src/main/res/values/strings.xml +4 -0
- package/android/common/src/main/res/xml/authenticator.xml +7 -0
- package/android/common/src/main/res/xml/syncadapter.xml +9 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +82 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +128 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +191 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +37 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +216 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +223 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +50 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +180 -0
- package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +16 -0
- package/android/dependencies.gradle +13 -0
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.h +41 -0
- package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +526 -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 +202 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.h +60 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +638 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.h +34 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +185 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.h +25 -0
- package/ios/common/BackgroundGeolocation/MAURBackgroundTaskManager.m +105 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.h +74 -0
- package/ios/common/BackgroundGeolocation/MAURConfig.m +485 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +49 -0
- package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +51 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURDistanceFilterLocationProvider.m +514 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.h +17 -0
- package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +97 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.h +59 -0
- package/ios/common/BackgroundGeolocation/MAURLocation.m +349 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.h +34 -0
- package/ios/common/BackgroundGeolocation/MAURLocationContract.m +35 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.h +53 -0
- package/ios/common/BackgroundGeolocation/MAURLocationManager.m +287 -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 +40 -0
- package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +250 -0
- package/ios/common/BackgroundGeolocation/MAURProviderDelegate.h +52 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.h +18 -0
- package/ios/common/BackgroundGeolocation/MAURRawLocationProvider.m +129 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.h +26 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +278 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.h +57 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteHelper.m +93 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +38 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +380 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.h +32 -0
- package/ios/common/BackgroundGeolocation/MAURSQLiteOpenHelper.m +276 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.h +20 -0
- package/ios/common/BackgroundGeolocation/MAURUncaughtExceptionLogger.m +62 -0
- package/ios/common/BackgroundGeolocation/Reachability.h +102 -0
- package/ios/common/BackgroundGeolocation/Reachability.m +475 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/CHANGELOG.md +2 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/LICENSE +21 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/README.md +135 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.h +80 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOLocationManager.m +147 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.h +30 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionActivity.m +42 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.h +99 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOMotionDetector.m +327 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.h +44 -0
- package/ios/common/BackgroundGeolocation/SOMotionDetector/SOStepDetector.m +94 -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.xcodeproj/project.pbxproj +760 -0
- package/ios/common/BackgroundGeolocationTests/Info.plist +24 -0
- package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +185 -0
- package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +161 -0
- package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +102 -0
- package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +216 -0
- package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +55 -0
- package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +43 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +102 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +41 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +240 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +84 -0
- package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +144 -0
- package/ios/common/CONTRIBUTORS.md +10 -0
- package/ios/common/LICENSE +191 -0
- package/ios/common/README.md +7 -0
- package/ios/common/scripts/xcode-refactor.js +184 -0
- package/package.json +44 -0
- package/plugin.xml +355 -0
- package/www/BackgroundGeolocation.d.ts +910 -0
- package/www/BackgroundGeolocation.js +247 -0
- package/www/radio.js +177 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MotionDetecter.m
|
|
3
|
+
// MotionDetection
|
|
4
|
+
//
|
|
5
|
+
// The MIT License (MIT)
|
|
6
|
+
//
|
|
7
|
+
// Created by : arturdev
|
|
8
|
+
// Copyright (c) 2014 SocialObjects Software. All rights reserved.
|
|
9
|
+
//
|
|
10
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
11
|
+
// this software and associated documentation files (the "Software"), to deal in
|
|
12
|
+
// the Software without restriction, including without limitation the rights to
|
|
13
|
+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
14
|
+
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
// subject to the following conditions:
|
|
16
|
+
//
|
|
17
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
// copies or substantial portions of the Software.
|
|
19
|
+
//
|
|
20
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
22
|
+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
23
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
24
|
+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
25
|
+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
|
26
|
+
|
|
27
|
+
#import "SOMotionDetector.h"
|
|
28
|
+
|
|
29
|
+
CGFloat kMinimumSpeed = 0.3f;
|
|
30
|
+
CGFloat kMaximumWalkingSpeed = 1.9f;
|
|
31
|
+
CGFloat kMaximumRunningSpeed = 7.5f;
|
|
32
|
+
CGFloat kMinimumRunningAcceleration = 3.5f;
|
|
33
|
+
|
|
34
|
+
@interface SOMotionDetector()
|
|
35
|
+
|
|
36
|
+
@property (strong, nonatomic) NSTimer *shakeDetectingTimer;
|
|
37
|
+
|
|
38
|
+
@property (strong, nonatomic) CLLocation *currentLocation;
|
|
39
|
+
@property (nonatomic) SOMotionType previousMotionType;
|
|
40
|
+
|
|
41
|
+
#pragma mark - Accelerometer manager
|
|
42
|
+
@property (strong, nonatomic) CMMotionManager *motionManager;
|
|
43
|
+
@property (strong, nonatomic) CMMotionActivityManager *motionActivityManager;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@end
|
|
47
|
+
|
|
48
|
+
@implementation SOMotionDetector
|
|
49
|
+
|
|
50
|
+
+ (SOMotionDetector *)sharedInstance
|
|
51
|
+
{
|
|
52
|
+
static SOMotionDetector *instance = nil;
|
|
53
|
+
static dispatch_once_t onceToken;
|
|
54
|
+
dispatch_once(&onceToken, ^{
|
|
55
|
+
instance = [[self alloc] init];
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return instance;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
- (id)init
|
|
62
|
+
{
|
|
63
|
+
self = [super init];
|
|
64
|
+
if (self) {
|
|
65
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
66
|
+
selector:@selector(handleLocationChangedNotification:)
|
|
67
|
+
name:LOCATION_DID_CHANGED_NOTIFICATION
|
|
68
|
+
object:nil];
|
|
69
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
70
|
+
selector:@selector(handleLocationWasPausedNotification:)
|
|
71
|
+
name:LOCATION_WAS_PAUSED_NOTIFICATION
|
|
72
|
+
object:nil];
|
|
73
|
+
self.activityDetectionInterval = 0.01f;
|
|
74
|
+
self.motionManager = [[CMMotionManager alloc] init];
|
|
75
|
+
_motionActivity = [[SOMotionActivity alloc] init];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return self;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
+ (BOOL)motionHardwareAvailable
|
|
82
|
+
{
|
|
83
|
+
static BOOL isAvailable = NO;
|
|
84
|
+
static dispatch_once_t onceToken;
|
|
85
|
+
dispatch_once(&onceToken, ^{
|
|
86
|
+
isAvailable = [CMMotionActivityManager isActivityAvailable];
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return isAvailable;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#pragma mark - Public Methods
|
|
93
|
+
- (void)startDetection
|
|
94
|
+
{
|
|
95
|
+
|
|
96
|
+
[self.motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
|
|
97
|
+
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error)
|
|
98
|
+
{
|
|
99
|
+
_acceleration = accelerometerData.acceleration;
|
|
100
|
+
[self calculateMotionType];
|
|
101
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
102
|
+
#pragma GCC diagnostic push
|
|
103
|
+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
104
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:accelerationChanged:)]) {
|
|
105
|
+
[self.delegate motionDetector:self accelerationChanged:self.acceleration];
|
|
106
|
+
}
|
|
107
|
+
#pragma GCC diagnostic pop
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (self.accelerationChangedBlock) {
|
|
111
|
+
self.accelerationChangedBlock (self.acceleration);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}];
|
|
115
|
+
|
|
116
|
+
if (self.useM7IfAvailable && [SOMotionDetector motionHardwareAvailable]) {
|
|
117
|
+
if (!self.motionActivityManager) {
|
|
118
|
+
self.motionActivityManager = [[CMMotionActivityManager alloc] init];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
[self.motionActivityManager startActivityUpdatesToQueue:[[NSOperationQueue alloc] init] withHandler:^(CMMotionActivity *activity) {
|
|
122
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
123
|
+
SOMotionType motionType;
|
|
124
|
+
if (activity.walking) {
|
|
125
|
+
motionType = MotionTypeWalking;
|
|
126
|
+
} else if (activity.running) {
|
|
127
|
+
motionType = MotionTypeRunning;
|
|
128
|
+
} else if (activity.automotive) {
|
|
129
|
+
motionType = MotionTypeAutomotive;
|
|
130
|
+
} else if (activity.stationary || activity.unknown) {
|
|
131
|
+
motionType = MotionTypeNotMoving;
|
|
132
|
+
} else {
|
|
133
|
+
motionType = MotionTypeUnknown;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
int confidence;
|
|
137
|
+
switch (activity.confidence) {
|
|
138
|
+
case CMMotionActivityConfidenceLow:
|
|
139
|
+
confidence = 20;
|
|
140
|
+
break;
|
|
141
|
+
case CMMotionActivityConfidenceMedium:
|
|
142
|
+
confidence = 40;
|
|
143
|
+
break;
|
|
144
|
+
case CMMotionActivityConfidenceHigh:
|
|
145
|
+
confidence = 80;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_motionActivity.motionType = motionType;
|
|
150
|
+
_motionActivity.confidence = activity.confidence;
|
|
151
|
+
|
|
152
|
+
// If type was changed, then call delegate method
|
|
153
|
+
if (motionType != self.previousMotionType) {
|
|
154
|
+
self.previousMotionType = motionType;
|
|
155
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:activityTypeChanged:)]) {
|
|
156
|
+
[self.delegate motionDetector:self activityTypeChanged:self.motionActivity];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (self.activityTypeChangedBlock) {
|
|
160
|
+
self.activityTypeChangedBlock (self.motionActivity);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
}];
|
|
166
|
+
} else {
|
|
167
|
+
[[SOLocationManager sharedInstance] start];
|
|
168
|
+
|
|
169
|
+
self.shakeDetectingTimer = [NSTimer scheduledTimerWithTimeInterval:self.activityDetectionInterval
|
|
170
|
+
target:self
|
|
171
|
+
selector:@selector(detectShaking)
|
|
172
|
+
userInfo:Nil
|
|
173
|
+
repeats:YES];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
- (void)stopDetection
|
|
178
|
+
{
|
|
179
|
+
[self.shakeDetectingTimer invalidate];
|
|
180
|
+
self.shakeDetectingTimer = nil;
|
|
181
|
+
|
|
182
|
+
[[SOLocationManager sharedInstance] stop];
|
|
183
|
+
[self.motionManager stopAccelerometerUpdates];
|
|
184
|
+
[self.motionActivityManager stopActivityUpdates];
|
|
185
|
+
_previousMotionType = 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#pragma mark - Customization Methods
|
|
189
|
+
- (void)setMinimumSpeed:(CGFloat)speed
|
|
190
|
+
{
|
|
191
|
+
kMinimumSpeed = speed;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
- (void)setMaximumWalkingSpeed:(CGFloat)speed
|
|
195
|
+
{
|
|
196
|
+
kMaximumWalkingSpeed = speed;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
- (void)setMaximumRunningSpeed:(CGFloat)speed
|
|
200
|
+
{
|
|
201
|
+
kMaximumRunningSpeed = speed;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
- (void)setMinimumRunningAcceleration:(CGFloat)acceleration
|
|
205
|
+
{
|
|
206
|
+
kMinimumRunningAcceleration = acceleration;
|
|
207
|
+
}
|
|
208
|
+
#pragma mark - Private Methods
|
|
209
|
+
- (void)calculateMotionType
|
|
210
|
+
{
|
|
211
|
+
SOMotionType motionType;
|
|
212
|
+
if (_currentSpeed < kMinimumSpeed) {
|
|
213
|
+
motionType = MotionTypeNotMoving;
|
|
214
|
+
} else if (_currentSpeed <= kMaximumWalkingSpeed) {
|
|
215
|
+
motionType = _isShaking ? MotionTypeRunning : MotionTypeWalking;
|
|
216
|
+
} else if (_currentSpeed <= kMaximumRunningSpeed) {
|
|
217
|
+
motionType = _isShaking ? MotionTypeRunning : MotionTypeAutomotive;
|
|
218
|
+
} else {
|
|
219
|
+
motionType = MotionTypeAutomotive;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
_motionActivity.motionType = motionType;
|
|
223
|
+
_motionActivity.confidence = 0;
|
|
224
|
+
|
|
225
|
+
// If type was changed, then call delegate method
|
|
226
|
+
if (motionType != self.previousMotionType) {
|
|
227
|
+
self.previousMotionType = motionType;
|
|
228
|
+
|
|
229
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
230
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:activityTypeChanged:)]) {
|
|
231
|
+
[self.delegate motionDetector:self activityTypeChanged:self.motionActivity];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (self.activityTypeChangedBlock) {
|
|
235
|
+
self.activityTypeChangedBlock (self.motionActivity);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
- (void)detectShaking
|
|
242
|
+
{
|
|
243
|
+
//Array for collecting acceleration for last one seconds period.
|
|
244
|
+
static NSMutableArray *shakeDataForOneSec = nil;
|
|
245
|
+
//Counter for calculating completion of one second interval
|
|
246
|
+
static float currentFiringTimeInterval = 0.0f;
|
|
247
|
+
|
|
248
|
+
currentFiringTimeInterval += 0.01f;
|
|
249
|
+
if (currentFiringTimeInterval < 1.0f) {// if one second time intervall not completed yet
|
|
250
|
+
if (!shakeDataForOneSec)
|
|
251
|
+
shakeDataForOneSec = [NSMutableArray array];
|
|
252
|
+
|
|
253
|
+
// Add current acceleration to array
|
|
254
|
+
NSValue *boxedAcceleration = [NSValue value:&_acceleration withObjCType:@encode(CMAcceleration)];
|
|
255
|
+
[shakeDataForOneSec addObject:boxedAcceleration];
|
|
256
|
+
} else {
|
|
257
|
+
// Now, when one second was elapsed, calculate shake count in this interval. If there will be at least one shake then
|
|
258
|
+
// we'll determine it as shaked in all this one second interval.
|
|
259
|
+
|
|
260
|
+
int shakeCount = 0;
|
|
261
|
+
for (NSValue *boxedAcceleration in shakeDataForOneSec) {
|
|
262
|
+
CMAcceleration acceleration;
|
|
263
|
+
[boxedAcceleration getValue:&acceleration];
|
|
264
|
+
|
|
265
|
+
/*********************************
|
|
266
|
+
* Detecting shaking
|
|
267
|
+
*********************************/
|
|
268
|
+
double accX_2 = powf(acceleration.x,2);
|
|
269
|
+
double accY_2 = powf(acceleration.y,2);
|
|
270
|
+
double accZ_2 = powf(acceleration.z,2);
|
|
271
|
+
|
|
272
|
+
double vectorSum = sqrt(accX_2 + accY_2 + accZ_2);
|
|
273
|
+
|
|
274
|
+
if (vectorSum >= kMinimumRunningAcceleration) {
|
|
275
|
+
shakeCount++;
|
|
276
|
+
}
|
|
277
|
+
/*********************************/
|
|
278
|
+
}
|
|
279
|
+
_isShaking = shakeCount > 0;
|
|
280
|
+
|
|
281
|
+
shakeDataForOneSec = nil;
|
|
282
|
+
currentFiringTimeInterval = 0.0f;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
#pragma mark - LocationManager notification handler
|
|
287
|
+
- (void)handleLocationChangedNotification:(NSNotification *)note
|
|
288
|
+
{
|
|
289
|
+
self.currentLocation = [SOLocationManager sharedInstance].lastLocation;
|
|
290
|
+
_currentSpeed = self.currentLocation.speed;
|
|
291
|
+
if (_currentSpeed < 0) {
|
|
292
|
+
_currentSpeed = 0;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
296
|
+
#pragma GCC diagnostic push
|
|
297
|
+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
298
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:locationChanged:)]) {
|
|
299
|
+
[self.delegate motionDetector:self locationChanged:self.currentLocation];
|
|
300
|
+
}
|
|
301
|
+
#pragma GCC diagnostic pop
|
|
302
|
+
|
|
303
|
+
if (self.locationChangedBlock) {
|
|
304
|
+
self.locationChangedBlock (self.currentLocation);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
[self calculateMotionType];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#pragma mark - LocationManager notification handler
|
|
312
|
+
- (void)handleLocationWasPausedNotification:(NSNotification *)note
|
|
313
|
+
{
|
|
314
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
315
|
+
#pragma GCC diagnostic push
|
|
316
|
+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
317
|
+
if (self.delegate && [self.delegate respondsToSelector:@selector(motionDetector:locationWasPaused:)]) {
|
|
318
|
+
[self.delegate motionDetector:self locationWasPaused:TRUE];
|
|
319
|
+
}
|
|
320
|
+
#pragma GCC diagnostic pop
|
|
321
|
+
|
|
322
|
+
if (self.locationWasPausedBlock) {
|
|
323
|
+
self.locationWasPausedBlock (TRUE);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
@end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SOMotionDetecter.h
|
|
3
|
+
// MotionDetection
|
|
4
|
+
//
|
|
5
|
+
// The MIT License (MIT)
|
|
6
|
+
//
|
|
7
|
+
// Created by : arturdev
|
|
8
|
+
// Copyright (c) 2014 SocialObjects Software. All rights reserved.
|
|
9
|
+
//
|
|
10
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
11
|
+
// this software and associated documentation files (the "Software"), to deal in
|
|
12
|
+
// the Software without restriction, including without limitation the rights to
|
|
13
|
+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
14
|
+
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
// subject to the following conditions:
|
|
16
|
+
//
|
|
17
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
// copies or substantial portions of the Software.
|
|
19
|
+
//
|
|
20
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
22
|
+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
23
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
24
|
+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
25
|
+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
|
26
|
+
|
|
27
|
+
#import <Foundation/Foundation.h>
|
|
28
|
+
|
|
29
|
+
@interface SOStepDetector : NSObject
|
|
30
|
+
|
|
31
|
+
+ (instancetype)sharedInstance;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Start accelerometer updates.
|
|
35
|
+
* @param callback Will be called every time when new step is detected
|
|
36
|
+
*/
|
|
37
|
+
- (void)startDetectionWithUpdateBlock:(void(^)(NSError *error))callback;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Stop motion manager accelerometer updates
|
|
41
|
+
*/
|
|
42
|
+
- (void)stopDetection;
|
|
43
|
+
|
|
44
|
+
@end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
//
|
|
3
|
+
// SOStepDetector.m
|
|
4
|
+
// MotionDetection
|
|
5
|
+
//
|
|
6
|
+
// Created by Artur on 5/15/15.
|
|
7
|
+
// Copyright (c) 2015 Artur Mkrtchyan. All rights reserved.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
#import <UIKit/UIKit.h>
|
|
11
|
+
#import "SOStepDetector.h"
|
|
12
|
+
#import <CoreMotion/CoreMotion.h>
|
|
13
|
+
|
|
14
|
+
#define kUpdateInterval 0.2f
|
|
15
|
+
@interface SOStepDetector()
|
|
16
|
+
|
|
17
|
+
@property (strong, nonatomic) CMMotionManager *motionManager;
|
|
18
|
+
@property (strong, nonatomic) NSOperationQueue* queue;
|
|
19
|
+
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
@implementation SOStepDetector
|
|
23
|
+
|
|
24
|
+
+ (instancetype)sharedInstance
|
|
25
|
+
{
|
|
26
|
+
static id instance;
|
|
27
|
+
static dispatch_once_t onceToken;
|
|
28
|
+
dispatch_once(&onceToken, ^{
|
|
29
|
+
instance = [self new];
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return instance;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (instancetype)init
|
|
36
|
+
{
|
|
37
|
+
self = [super init];
|
|
38
|
+
|
|
39
|
+
self.motionManager = [CMMotionManager new];
|
|
40
|
+
|
|
41
|
+
self.motionManager.accelerometerUpdateInterval = kUpdateInterval;
|
|
42
|
+
self.motionManager.deviceMotionUpdateInterval = kUpdateInterval;
|
|
43
|
+
self.motionManager.gyroUpdateInterval = kUpdateInterval;
|
|
44
|
+
self.motionManager.magnetometerUpdateInterval = kUpdateInterval;
|
|
45
|
+
self.motionManager.showsDeviceMovementDisplay = YES;
|
|
46
|
+
|
|
47
|
+
self.queue = [NSOperationQueue new];
|
|
48
|
+
self.queue.maxConcurrentOperationCount = 1;
|
|
49
|
+
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)startDetectionWithUpdateBlock:(void (^)(NSError *))callback
|
|
54
|
+
{
|
|
55
|
+
if (self.motionManager.isAccelerometerActive) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
[self.motionManager startAccelerometerUpdatesToQueue:self.queue
|
|
60
|
+
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
|
|
61
|
+
if (error) {
|
|
62
|
+
if (callback) {
|
|
63
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
64
|
+
callback (error);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return ;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
CMAcceleration acceleration = accelerometerData.acceleration;
|
|
71
|
+
|
|
72
|
+
CGFloat strength = 1.2f;
|
|
73
|
+
BOOL isStep = NO;
|
|
74
|
+
if (fabs(acceleration.x) > strength || fabs(acceleration.y) > strength || fabs(acceleration.z) > strength) {
|
|
75
|
+
isStep = YES;
|
|
76
|
+
}
|
|
77
|
+
if (isStep) {
|
|
78
|
+
if (callback) {
|
|
79
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
80
|
+
callback (nil);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
- (void)stopDetection
|
|
88
|
+
{
|
|
89
|
+
if (self.motionManager.isAccelerometerActive) {
|
|
90
|
+
[self.motionManager stopAccelerometerUpdates];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Objective-C SQL Query Builder
|
|
2
|
+
|
|
3
|
+
This Objective-C SQLite project is a lightweight library that offers more than just a set of [SQLite](http://www.sqlite.org/)
|
|
4
|
+
wrapper classes. It is divided up into five parts. The first part consists of a set of Objective-C classes that handle
|
|
5
|
+
communications with an SQLite database. Inside the "src" folder, these Objective-C classes are further subdivided into five
|
|
6
|
+
folders. The "db" folder (formerly, the "dao" folder) contains an SQLite wrapper class that easily manages the database
|
|
7
|
+
connection. The "ext" folder contains some class extensions. The "sql" folder contains a collection of SQL builder classes
|
|
8
|
+
that can be used to construct well-formed SQL statements for SQLite via a plethora of convenience methods similar to those
|
|
9
|
+
found in LINQ. Likewise, the "orm" folder has an assortment of classes that can control and manipulate data within an SQLite
|
|
10
|
+
database via the Active Record design pattern. And, the "util" folder contains a set of various helper classes. The
|
|
11
|
+
second part consists of an easy-to-read API, which both documents and diagrams each Objective-C class and XML/DTD file.
|
|
12
|
+
The third part consists of a BASH script that can be used to generate the necessary ORM models using the SQLite's database
|
|
13
|
+
schema. The fourth part consists of the database configuration files for the SQLite database connection. The final part
|
|
14
|
+
has the schema for handling XML to DDL.
|
|
15
|
+
|
|
16
|
+
All classes are designed to be used in iPhone/iOS applications. The classes in the "ARC" branches are compliant with iOS 5's
|
|
17
|
+
[automatic reference counting](http://clang.llvm.org/docs/AutomaticReferenceCounting.html). For projects still using Retains,
|
|
18
|
+
Releases, and Autoreleases (i.e. Pre-ARC) use the classes in the "RRA" branches.
|
|
19
|
+
|
|
20
|
+
## Supported Platforms
|
|
21
|
+
|
|
22
|
+
- Mac OS X 10.7+
|
|
23
|
+
- iOS 4.0+
|
|
24
|
+
|
|
25
|
+
## Motivation
|
|
26
|
+
|
|
27
|
+
The goal of this project is to make these classes the "de facto" standard for communicating with SQLite databases on
|
|
28
|
+
iPhone/iOS devices.
|
|
29
|
+
|
|
30
|
+
With the abundance of third-party libraries for Objective-C, it was apparent that a successful SQLite library needs to
|
|
31
|
+
be simple to learn and intuitive. It must also be cleanly written with clear naming conventions and must be well-documented
|
|
32
|
+
for too many SQLite libraries are hard to understand and are not user-friendly. For these reasons, this SQLite library was
|
|
33
|
+
written.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
The following is a short-list of some of the features:
|
|
38
|
+
|
|
39
|
+
* [Automatic reference counting](http://longweekendmobile.com/2011/09/07/objc-automatic-reference-counting-in-xcode-explained/);
|
|
40
|
+
* Cleanly wraps-up the sqlite3 C based functions.
|
|
41
|
+
* Automatically places the SQLite database in the "Document" directory.
|
|
42
|
+
* Allows for read-only databases.
|
|
43
|
+
* Provides multi-threading support for asynchronous SQLite database calls;
|
|
44
|
+
* Utilizes a PLIST file for configuring SQLite database connections;
|
|
45
|
+
* Allows database privileges to be restricted.
|
|
46
|
+
* Has an easy to use SQLite database connection pool.
|
|
47
|
+
* Capable of executing an SQL statement with one line of code.
|
|
48
|
+
* Able to execute more than one SQL statement at a time.
|
|
49
|
+
* Has a huge collection of SQL builder classes with methods that mimic their SQL statement equivalents.
|
|
50
|
+
* Converts XML to DDL/SQL statements.
|
|
51
|
+
* Helps ensure that SQL statements are well-formed.
|
|
52
|
+
* Supports all major Objective-C datatypes, including NSNull, NSNumber, NSDecimalNumber, NSString, NSData, and NSDate.
|
|
53
|
+
* Sanitizes data using best practices.
|
|
54
|
+
* Handles most complex queries and works with raw SQL statements.
|
|
55
|
+
* Has a powerful SQLite tokenizer.
|
|
56
|
+
* Contains a message digest to hash strings using md2, md4, md5, sha1, sha224, sha256, sha384, and sha512.
|
|
57
|
+
* Has a data access layer (DAL) that offers Object Relational Mapping (ORM).
|
|
58
|
+
* Data access objects (DAO) handle composite primary keys.
|
|
59
|
+
* Via a Bash script, models (i.e. Active Records) can be auto-generated for each table in the SQLite database.
|
|
60
|
+
* Handles foreign keys via true lazy loading.
|
|
61
|
+
* Requires only those Objective-C classes that are absolutely needed.
|
|
62
|
+
* Classes are easily extendible.
|
|
63
|
+
* Has clear API documentation generated via [Doxygen](http://www.stack.nl/~dimitri/doxygen/).
|
|
64
|
+
|
|
65
|
+
## Getting Started
|
|
66
|
+
|
|
67
|
+
Using these classes in an Xcode project is easy to do. Here is how:
|
|
68
|
+
|
|
69
|
+
1. Download the source code via Github as a tarball (i.e. .tar.gz).
|
|
70
|
+
2. Navigate to the tarball in Finder.
|
|
71
|
+
3. Unarchive the tarball by double-clicking it in a Finder window.
|
|
72
|
+
4. Open an Xcode project.
|
|
73
|
+
5. Right-click on the "Classes" folder and click on the "Add >> Existing Files..." option.
|
|
74
|
+
6. Highlight the files, then click the "Add" button.
|
|
75
|
+
7. Check "Copy items into destination group's folder (if needed)".
|
|
76
|
+
8. Select "Default" for the "Reference Type".
|
|
77
|
+
9. Choose "Recursively create groups for any added folders".
|
|
78
|
+
10. Click "Add".
|
|
79
|
+
|
|
80
|
+
### Required Files
|
|
81
|
+
|
|
82
|
+
A lot of work has gone into making the classes in this repository as independent as possible; however, a few
|
|
83
|
+
dependencies just can't be avoided. To make life easier, the following SDK import files have been created to
|
|
84
|
+
make the implementation process as painless as possible:
|
|
85
|
+
|
|
86
|
+
* ZIMDaoSdk.h
|
|
87
|
+
* ZIMSqlSdk.h
|
|
88
|
+
* ZIMOrmSdk.h
|
|
89
|
+
|
|
90
|
+
Based on which SDK is needed, only those classes listed (i.e. imported) in the SDK import file are needed to be
|
|
91
|
+
added to the respective Xcode project.
|
|
92
|
+
|
|
93
|
+
### Required Frameworks
|
|
94
|
+
|
|
95
|
+
To use these Objective-C classes in an Xcode project, add the following framework:
|
|
96
|
+
|
|
97
|
+
* libsqlite3.dylib
|
|
98
|
+
|
|
99
|
+
### Documentation
|
|
100
|
+
|
|
101
|
+
All classes are heavily documented using [HeaderDoc](http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/HeaderDoc/intro/intro.html#//apple_ref/doc/uid/TP40001215-CH345-SW1).
|
|
102
|
+
You can get familiar with each class by simply looking at the API or by opening its respective ".h" file. Similarly,
|
|
103
|
+
all XML/DTD files are documented using [DTDDoc](http://dtddoc.sourceforge.net). You can also find more information on
|
|
104
|
+
this repository's Wiki.
|
|
105
|
+
|
|
106
|
+
### Tutorials / Examples
|
|
107
|
+
|
|
108
|
+
Checkout this SQLite repository's Wiki for a handful of examples. There, you will find examples on how to make
|
|
109
|
+
an SQLite database connection and how to build [DCL, DDL, DML, and TCL commands](http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/statements_1001.htm)
|
|
110
|
+
(including Create, Read, Update, and Delete (CRUD) statements). The Wiki also has tutorials on how to use Object
|
|
111
|
+
Relational Mapping (ORM) and how to generate the necessary models (i.e. active records).
|
|
112
|
+
|
|
113
|
+
### Further Assistance
|
|
114
|
+
|
|
115
|
+
If you need further assistance in implementing these classes, you can always send an email to oss@ziminji.com with
|
|
116
|
+
any questions that you may have about this repository. Any frequently asked questions (FAQ) will be posted on this
|
|
117
|
+
repository's Wiki.
|
|
118
|
+
|
|
119
|
+
You can also seek assistance via the blogs. A great Web site for community assistance is [Stack Overflow](http://stackoverflow.com).
|
|
120
|
+
|
|
121
|
+
## Reporting Bugs & Making Recommendations
|
|
122
|
+
|
|
123
|
+
Help debug the code in repository by reporting any bugs. The more detailed the report the better. If you have a bug-fix
|
|
124
|
+
or a unit-test, please create an issue under the "Issues" tab of this repository and someone will follow-up with it as
|
|
125
|
+
soon as possible.
|
|
126
|
+
|
|
127
|
+
Likewise, if you would like to make a recommendation on how to improve the code in this repository, take the time to send
|
|
128
|
+
a message so that it can be considered for an upcoming release. Or, if you would like to contribute to the development of
|
|
129
|
+
this Objective-C SQLite repository, go ahead and create a fork.
|
|
130
|
+
|
|
131
|
+
You can also email any bug-fixes, unit-tests, or recommendations to oss@ziminji.com.
|
|
132
|
+
|
|
133
|
+
### Known Issues
|
|
134
|
+
|
|
135
|
+
Usually, code is not posted to this SQLite repository unless it works; however, there are times when some code may get
|
|
136
|
+
posted even though it still contains some bugs. When this occurs, every attempt will be made to list these known bugs
|
|
137
|
+
in this README (if they are not already listed under the "Issues" tab).
|
|
138
|
+
|
|
139
|
+
At the current time, there are no known bugs. However, the "XML to DDL" schema processing is still being developed.
|
|
140
|
+
|
|
141
|
+
### Updates
|
|
142
|
+
|
|
143
|
+
This Objective-C SQLite project is updated frequently with bug-fixes and new features. Be sure to add this repository
|
|
144
|
+
to your watch list so that you can be notified when such updates are made. You can also request email notifications
|
|
145
|
+
regarding updates by emailing oss@ziminji.com.
|
|
146
|
+
|
|
147
|
+
## Future Development
|
|
148
|
+
|
|
149
|
+
This project is under heavy development. There are development plans to add:
|
|
150
|
+
|
|
151
|
+
* Improved functionality to parse "XML to DDL" schema and raw SQLite statements into their SQL builder class equivalents;
|
|
152
|
+
* More utilities (e.g. classes to handle validation, filtering, imports, exports, pagination, partitioning, and migration);
|
|
153
|
+
* A database encryption layer for password protecting an SQLite database;
|
|
154
|
+
* Unit-tests; and,
|
|
155
|
+
* Additional tutorials and examples.
|
|
156
|
+
|
|
157
|
+
Help expand this list with your feedback.
|
|
158
|
+
|
|
159
|
+
## License (Apache v2.0)
|
|
160
|
+
|
|
161
|
+
>Copyright 2011-2015 Ziminji
|
|
162
|
+
>
|
|
163
|
+
>Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the
|
|
164
|
+
>License. You may obtain a copy of the License at:
|
|
165
|
+
>
|
|
166
|
+
>[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
|
167
|
+
>
|
|
168
|
+
>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
|
|
169
|
+
>"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
|
170
|
+
>language governing permissions and limitations under the License.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2011-2015 Ziminji
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at:
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#import <Foundation/Foundation.h>
|
|
18
|
+
|
|
19
|
+
/*!
|
|
20
|
+
@category NSString (ZIMString)
|
|
21
|
+
@discussion This category extends the functionality of the NSString class.
|
|
22
|
+
@updated 2011-07-16
|
|
23
|
+
*/
|
|
24
|
+
@interface NSString (ZIMString)
|
|
25
|
+
/*!
|
|
26
|
+
@method matchesRegex:options:
|
|
27
|
+
@discussion This method determines whether the pattern is matched.
|
|
28
|
+
@param pattern The regular expression to be used.
|
|
29
|
+
@param options The options to be used.
|
|
30
|
+
@return A boolean value denoting whether the pattern was matched.
|
|
31
|
+
@updated 2012-03-20
|
|
32
|
+
@see http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html
|
|
33
|
+
@see http://quickies.seriot.ch/index.php?id=279
|
|
34
|
+
*/
|
|
35
|
+
- (BOOL) matchesRegex: (NSString *)pattern options: (NSRegularExpressionOptions)options;
|
|
36
|
+
/*!
|
|
37
|
+
@method capitalizeFirstCharacterInString:
|
|
38
|
+
@discussion This method will capitalize the first letter in the specified string.
|
|
39
|
+
@param string The string to be modified.
|
|
40
|
+
@return The modified string.
|
|
41
|
+
@updated 2011-06-29
|
|
42
|
+
@see http://stackoverflow.com/questions/883897/easy-way-to-set-a-single-character-of-an-nsstring-to-uppercase
|
|
43
|
+
*/
|
|
44
|
+
+ (NSString *) capitalizeFirstCharacterInString: (NSString *)string;
|
|
45
|
+
/*!
|
|
46
|
+
@method firstTokenInString:scanUpToCharactersFromSet:
|
|
47
|
+
@discussion This method returns the first token found in the specified string.
|
|
48
|
+
@param string The string to be parsed.
|
|
49
|
+
@param stopSet The set of characters up to which to scan.
|
|
50
|
+
@return The first token found.
|
|
51
|
+
@updated 2011-06-29
|
|
52
|
+
*/
|
|
53
|
+
+ (NSString *) firstTokenInString: (NSString *)string scanUpToCharactersFromSet: (NSCharacterSet *)stopSet;
|
|
54
|
+
|
|
55
|
+
@end
|