From 922260c5ff6d57b3940884ffe4fcc3b7e8917150 Mon Sep 17 00:00:00 2001 From: Yuuki Nishiyama Date: Tue, 20 Nov 2018 12:47:21 +0200 Subject: [PATCH] first commit --- .gitignore | 5 +- Example/Tests/Tests.swift | 2 +- .../project.pbxproj | 27 ++- .../ViewController.swift | 14 ++ LICENSE | 20 +-- README.md | 47 +++-- ...eframework.ios.sensor.magnetometer.podspec | 15 +- .../Classes/MagnetometerSensor.swift | 162 ++++++++++++++++++ .../Classes/ReplaceMe.swift | 0 .../Classes/model/MagnetometerData.swift | 30 ++++ 10 files changed, 283 insertions(+), 39 deletions(-) create mode 100644 com.awareframework.ios.sensor.magnetometer/Classes/MagnetometerSensor.swift delete mode 100644 com.awareframework.ios.sensor.magnetometer/Classes/ReplaceMe.swift create mode 100644 com.awareframework.ios.sensor.magnetometer/Classes/model/MagnetometerData.swift diff --git a/.gitignore b/.gitignore index 93c86d3..182890d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ Carthage/Build # Note: if you ignore the Pods directory, make sure to uncomment # `pod install` in .travis.yml # -# Pods/ +Pods/ +Podfile.lock +Pods/ +com.awareframework.ios.sensor.magnetometer.xcworkspace/ diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift index 9251aee..dd6781a 100644 --- a/Example/Tests/Tests.swift +++ b/Example/Tests/Tests.swift @@ -1,5 +1,5 @@ import XCTest -import com.awareframework.ios.sensor.magnetometer +import com_awareframework_ios_sensor_magnetometer class Tests: XCTestCase { diff --git a/Example/com.awareframework.ios.sensor.magnetometer.xcodeproj/project.pbxproj b/Example/com.awareframework.ios.sensor.magnetometer.xcodeproj/project.pbxproj index 22a98b4..54d5867 100644 --- a/Example/com.awareframework.ios.sensor.magnetometer.xcodeproj/project.pbxproj +++ b/Example/com.awareframework.ios.sensor.magnetometer.xcodeproj/project.pbxproj @@ -42,10 +42,10 @@ 607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; 7BCE819A2BB2741BBEF600BF /* Pods-com.awareframework.ios.sensor.magnetometer_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-com.awareframework.ios.sensor.magnetometer_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-com.awareframework.ios.sensor.magnetometer_Example/Pods-com.awareframework.ios.sensor.magnetometer_Example.release.xcconfig"; sourceTree = ""; }; 8133371A7168CAA5F8EEB9B1 /* Pods_com_awareframework_ios_sensor_magnetometer_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_com_awareframework_ios_sensor_magnetometer_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - BDC90A7A9793C44838ED7DA2 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; + BDC90A7A9793C44838ED7DA2 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; DB709AD932E4A928BCB2DF6E /* Pods_com_awareframework_ios_sensor_magnetometer_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_com_awareframework_ios_sensor_magnetometer_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - E18E8290A0994804BC467432 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = ""; }; - F3FD70760ABD87C95B1DD33C /* com.awareframework.ios.sensor.magnetometer.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = com.awareframework.ios.sensor.magnetometer.podspec; path = ../com.awareframework.ios.sensor.magnetometer.podspec; sourceTree = ""; }; + E18E8290A0994804BC467432 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; + F3FD70760ABD87C95B1DD33C /* com.awareframework.ios.sensor.magnetometer.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = com.awareframework.ios.sensor.magnetometer.podspec; path = ../com.awareframework.ios.sensor.magnetometer.podspec; sourceTree = ""; }; FF9714D43A4F9A99E9E8B4BF /* Pods-com.awareframework.ios.sensor.magnetometer_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-com.awareframework.ios.sensor.magnetometer_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-com.awareframework.ios.sensor.magnetometer_Tests/Pods-com.awareframework.ios.sensor.magnetometer_Tests.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -212,6 +212,7 @@ TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + DevelopmentTeam = FH352PYMNC; LastSwiftMigration = 0900; }; 607FACE41AFB9204008FA782 = { @@ -314,12 +315,24 @@ ); inputPaths = ( "${SRCROOT}/Pods/Target Support Files/Pods-com.awareframework.ios.sensor.magnetometer_Example/Pods-com.awareframework.ios.sensor.magnetometer_Example-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Networking/Networking.framework", + "${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework", + "${BUILT_PRODUCTS_DIR}/Realm/Realm.framework", + "${BUILT_PRODUCTS_DIR}/RealmSwift/RealmSwift.framework", + "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework", + "${BUILT_PRODUCTS_DIR}/com.awareframework.ios.sensor.core/com_awareframework_ios_sensor_core.framework", "${BUILT_PRODUCTS_DIR}/com.awareframework.ios.sensor.magnetometer/com_awareframework_ios_sensor_magnetometer.framework", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( ); outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Networking.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RealmSwift.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/com_awareframework_ios_sensor_core.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/com_awareframework_ios_sensor_magnetometer.framework", ); runOnlyForDeploymentPostprocessing = 0; @@ -422,7 +435,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -468,7 +481,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -481,7 +494,9 @@ baseConfigurationReference = 2C681EC0B5C4CDAB17028DA2 /* Pods-com.awareframework.ios.sensor.magnetometer_Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = FH352PYMNC; INFOPLIST_FILE = com.awareframework.ios.sensor.magnetometer/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; @@ -496,7 +511,9 @@ baseConfigurationReference = 7BCE819A2BB2741BBEF600BF /* Pods-com.awareframework.ios.sensor.magnetometer_Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = FH352PYMNC; INFOPLIST_FILE = com.awareframework.ios.sensor.magnetometer/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; diff --git a/Example/com.awareframework.ios.sensor.magnetometer/ViewController.swift b/Example/com.awareframework.ios.sensor.magnetometer/ViewController.swift index 2e9b2d2..3896197 100644 --- a/Example/com.awareframework.ios.sensor.magnetometer/ViewController.swift +++ b/Example/com.awareframework.ios.sensor.magnetometer/ViewController.swift @@ -7,14 +7,28 @@ // import UIKit +import com_awareframework_ios_sensor_magnetometer class ViewController: UIViewController { + + var sensor:MagnetometerSensor? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. + sensor = MagnetometerSensor.init(MagnetometerSensor.Config().apply{config in + config.debug = true + config.sensorObserver = Observer() + }) + sensor?.start() } + class Observer:MagnetometerObserver { + func onChanged(data: MagnetometerData) { + print(data) + } + } + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. diff --git a/LICENSE b/LICENSE index 9d90e14..baafd0f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,19 +1,5 @@ -Copyright (c) 2018 tetujin +Copyright (c) 2018 AWARE Mobile Context Instrumentation Middleware/Framework (http://www.awareframework.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/README.md b/README.md index d16d490..795f926 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# com.awareframework.ios.sensor.magnetometer +# com.aware.ios.sensor.magnetometer -[![CI Status](https://img.shields.io/travis/tetujin/com.awareframework.ios.sensor.magnetometer.svg?style=flat)](https://travis-ci.org/tetujin/com.awareframework.ios.sensor.magnetometer) -[![Version](https://img.shields.io/cocoapods/v/com.awareframework.ios.sensor.magnetometer.svg?style=flat)](https://cocoapods.org/pods/com.awareframework.ios.sensor.magnetometer) -[![License](https://img.shields.io/cocoapods/l/com.awareframework.ios.sensor.magnetometer.svg?style=flat)](https://cocoapods.org/pods/com.awareframework.ios.sensor.magnetometer) -[![Platform](https://img.shields.io/cocoapods/p/com.awareframework.ios.sensor.magnetometer.svg?style=flat)](https://cocoapods.org/pods/com.awareframework.ios.sensor.magnetometer) +[![CI Status](https://img.shields.io/travis/tetujin/com.aware.ios.sensor.magnetometer.svg?style=flat)](https://travis-ci.org/tetujin/com.aware.ios.sensor.magnetometer) +[![Version](https://img.shields.io/cocoapods/v/com.aware.ios.sensor.magnetometer.svg?style=flat)](https://cocoapods.org/pods/com.aware.ios.sensor.magnetometer) +[![License](https://img.shields.io/cocoapods/l/com.aware.ios.sensor.magnetometer.svg?style=flat)](https://cocoapods.org/pods/com.aware.ios.sensor.magnetometer) +[![Platform](https://img.shields.io/cocoapods/p/com.aware.ios.sensor.magnetometer.svg?style=flat)](https://cocoapods.org/pods/com.aware.ios.sensor.magnetometer) ## Example @@ -13,17 +13,44 @@ To run the example project, clone the repo, and run `pod install` from the Examp ## Installation -com.awareframework.ios.sensor.magnetometer is available through [CocoaPods](https://cocoapods.org). To install -it, simply add the following line to your Podfile: +com.aware.ios.sensor.magnetometer is available through [CocoaPods](https://cocoapods.org). +1. To install it, simply add the following line to your Podfile: ```ruby -pod 'com.awareframework.ios.sensor.magnetometer' +pod 'com.aware.ios.sensor.magnetometer' +``` + +2. Import com.aware.ios.sensor.magnetometer library into your source code. +```swift +import com_aware_ios_sensor_magnetometer +``` + +## Example usage +```swift +var magnetometer = MagnetometerSensor.init( MagnetometerSensor.Config().apply{ config in + config.debug = true + config.sensorObserver = Observer() +}) +magnetometer?.start() +``` + +```swift +class Observer:MagnetometerObserver { + func onChanged(data:MagnetometerData){ + // Your code here.. + } +} ``` ## Author -tetujin, tetujin@ht.sfc.keio.ac.jp +Yuuki Nishiyama, tetujin@ht.sfc.keio.ac.jp ## License -com.awareframework.ios.sensor.magnetometer is available under the MIT license. See the LICENSE file for more info. +Copyright (c) 2018 AWARE Mobile Context Instrumentation Middleware/Framework (http://www.awareframework.com) + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + diff --git a/com.awareframework.ios.sensor.magnetometer.podspec b/com.awareframework.ios.sensor.magnetometer.podspec index 87b802d..64fb8dd 100644 --- a/com.awareframework.ios.sensor.magnetometer.podspec +++ b/com.awareframework.ios.sensor.magnetometer.podspec @@ -21,14 +21,16 @@ Pod::Spec.new do |s| TODO: Add long description of the pod here. DESC - s.homepage = 'https://github.com/tetujin/com.awareframework.ios.sensor.magnetometer' + s.homepage = 'https://github.com/awareframework/com.awareframework.ios.sensor.magnetometer' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' - s.license = { :type => 'MIT', :file => 'LICENSE' } + s.license = { :type => 'Apache2', :file => 'LICENSE' } s.author = { 'tetujin' => 'tetujin@ht.sfc.keio.ac.jp' } - s.source = { :git => 'https://github.com/tetujin/com.awareframework.ios.sensor.magnetometer.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/awareframework/com.awareframework.ios.sensor.magnetometer.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/' - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '10.0' + + s.swift_version = '4.0' s.source_files = 'com.awareframework.ios.sensor.magnetometer/Classes/**/*' @@ -37,6 +39,9 @@ TODO: Add long description of the pod here. # } # s.public_header_files = 'Pod/Classes/**/*.h' - # s.frameworks = 'UIKit', 'MapKit' + s.frameworks = 'CoreMotion' #'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' + + s.dependency 'com.awareframework.ios.sensor.core' + end diff --git a/com.awareframework.ios.sensor.magnetometer/Classes/MagnetometerSensor.swift b/com.awareframework.ios.sensor.magnetometer/Classes/MagnetometerSensor.swift new file mode 100644 index 0000000..bbb90ed --- /dev/null +++ b/com.awareframework.ios.sensor.magnetometer/Classes/MagnetometerSensor.swift @@ -0,0 +1,162 @@ +// +// MagnetometerSensor.swift +// com.aware.ios.sensor.magnetometer +// +// Created by Yuuki Nishiyama on 2018/10/30. +// + +import UIKit +import CoreMotion +import SwiftyJSON +import com_awareframework_ios_sensor_core + +extension Notification.Name{ + public static let actionAwareMagnetometer = Notification.Name(MagnetometerSensor.ACTION_AWARE_MAGNETOMETER) + public static let actionAwareMagnetometerStart = Notification.Name(MagnetometerSensor.ACTION_AWARE_MAGNETOMETER_START) + public static let actionAwareMagnetometerStop = Notification.Name(MagnetometerSensor.ACTION_AWARE_MAGNETOMETER_STOP) + public static let actionAwareMagnetometerSetLabel = Notification.Name(MagnetometerSensor.ACTION_AWARE_MAGNETOMETER_SET_LABEL) + public static let actionAwareMagnetometerSync = Notification.Name(MagnetometerSensor.ACTION_AWARE_MAGNETOMETER_SYNC) +} + +public protocol MagnetometerObserver{ + func onChanged(data:MagnetometerData) +} + +extension MagnetometerSensor{ + public static var TAG = "AWARE::Magnetometer" + + public static var ACTION_AWARE_MAGNETOMETER = "ACTION_AWARE_MAGNETOMETER" + + public static var ACTION_AWARE_MAGNETOMETER_START = "com.awareframework.android.sensor.magnetometer.SENSOR_START" + public static var ACTION_AWARE_MAGNETOMETER_STOP = "com.awareframework.android.sensor.magnetometer.SENSOR_STOP" + + public static var ACTION_AWARE_MAGNETOMETER_SET_LABEL = "com.awareframework.android.sensor.magnetometer.ACTION_AWARE_MAGNETOMETER_SET_LABEL" + public static var EXTRA_LABEL = "label" + + public static var ACTION_AWARE_MAGNETOMETER_SYNC = "com.awareframework.android.sensor.magnetometer.SENSOR_SYNC" +} + +public class MagnetometerSensor: AwareSensor { + var CONFIG = Config() + var motion = CMMotionManager() + var LAST_DATA:CMMagneticField? + var LAST_TS:Double = 0.0 + var LAST_SAVE:Double = 0.0 + public var dataBuffer = Array() + + public class Config:SensorConfig{ + /** + * For real-time observation of the sensor data collection. + */ + public var sensorObserver: MagnetometerObserver? = nil + + /** + * Magnetometer interval in hertz per second: e.g. + * + * 0 - fastest + * 1 - sample per second + * 5 - sample per second + * 20 - sample per second + */ + public var interval: Int = 5 + + /** + * Period to save data in minutes. (optional) + */ + public var period: Double = 1 + + /** + * Magnetometer threshold (float). Do not record consecutive points if + * change in value is less than the set value. + */ + public var threshold: Double = 0.0 + + public override init(){} + + public init(_ json:JSON){ + + } + + public func apply(closure:(_ config: MagnetometerSensor.Config) -> Void) -> Self { + closure(self) + return self + } + } + + override convenience init(){ + self.init(MagnetometerSensor.Config()) + } + + public init(_ config:MagnetometerSensor.Config){ + super.init() + self.CONFIG = config + self.initializeDbEngine(config: config) + if config.debug{ print(MagnetometerSensor.TAG, "Magnetometer sensor is created. ") } + } + + public override func start() { + if self.motion.isMagnetometerAvailable && !self.motion.isMagnetometerActive{ + self.motion.magnetometerUpdateInterval = 1.0/Double(CONFIG.interval) + self.motion.startMagnetometerUpdates(to: .main) { (magnetometerData, error) in + if let magData = magnetometerData { + let x = magData.magneticField.x + let y = magData.magneticField.y + let z = magData.magneticField.z + if let lastData = self.LAST_DATA { + if self.CONFIG.threshold > 0 && + abs(x - lastData.x) < self.CONFIG.threshold && + abs(y - lastData.y) < self.CONFIG.threshold && + abs(z - lastData.z) < self.CONFIG.threshold { + return + } + } + self.LAST_DATA = magData.magneticField + + let currentTime:Double = Date().timeIntervalSince1970 + self.LAST_TS = currentTime + + let data = MagnetometerData() + data.timestamp = Int64(currentTime*1000) + data.x = magData.magneticField.x + data.y = magData.magneticField.y + data.z = magData.magneticField.z + data.eventTimestamp = Int64(magData.timestamp*1000) + + if let observer = self.CONFIG.sensorObserver { + observer.onChanged(data: data) + } + + self.dataBuffer.append(data) + + if currentTime > self.LAST_SAVE + (self.CONFIG.period * 60) { + return + } + + let dataArray = Array(self.dataBuffer) + self.dbEngine?.save(dataArray, MagnetometerData.TABLE_NAME) + self.notificationCenter.post(name: .actionAwareMagnetometer, object: nil) + + self.dataBuffer.removeAll() + self.LAST_SAVE = currentTime + } + } + self.notificationCenter.post(name: .actionAwareMagnetometerStart, object: nil) + } + } + + public override func stop() { + if motion.isMagnetometerAvailable && motion.isMagnetometerActive { + motion.stopMagnetometerUpdates() + self.notificationCenter.post(name: .actionAwareMagnetometerStop, object: nil) + } + } + + public override func sync(force: Bool = false) { + if let engine = self.dbEngine{ + engine.startSync(MagnetometerData.TABLE_NAME, DbSyncConfig.init().apply(closure: { config in + config.debug = self.CONFIG.debug + })) + self.notificationCenter.post(name: .actionAwareMagnetometerSync, object: nil) + } + } +} diff --git a/com.awareframework.ios.sensor.magnetometer/Classes/ReplaceMe.swift b/com.awareframework.ios.sensor.magnetometer/Classes/ReplaceMe.swift deleted file mode 100644 index e69de29..0000000 diff --git a/com.awareframework.ios.sensor.magnetometer/Classes/model/MagnetometerData.swift b/com.awareframework.ios.sensor.magnetometer/Classes/model/MagnetometerData.swift new file mode 100644 index 0000000..56f410a --- /dev/null +++ b/com.awareframework.ios.sensor.magnetometer/Classes/model/MagnetometerData.swift @@ -0,0 +1,30 @@ +// +// MagnetometerData.swift +// com.aware.ios.sensor.magnetometer +// +// Created by Yuuki Nishiyama on 2018/10/30. +// + +import UIKit +import com_awareframework_ios_sensor_core + +public class MagnetometerData: AwareObject { + + public static var TABLE_NAME = "magnetometerData" + + @objc dynamic public var x:Double = 0.0 + @objc dynamic public var y:Double = 0.0 + @objc dynamic public var z:Double = 0.0 + @objc dynamic public var eventTimestamp:Int64 = 0 + @objc dynamic public var accuracy:Int = 0 + + public override func toDictionary() -> Dictionary { + var dict = super.toDictionary() + dict["x"] = x + dict["y"] = y + dict["z"] = z + dict["eventTimestamp"] = eventTimestamp + dict["accuracy"] = accuracy + return dict + } +}