Aware Activity Recognition (com.awareframework.ios.sensor.activityrecognition) is a plugin for AWARE Framework which is one of an open-source context-aware instrument. This plugin allows us to manage motion activity data (such as running, walking, and automotive) that is provided by iOS CMMotionActivityManager.
iOS 13 or later
You can integrate this framework into your project via Swift Package Manager (SwiftPM) or CocoaPods.
-
Open Package Manager Windows
- Open
Xcode-> SelectMenu Bar->File->App Package Dependencies...
- Open
-
Find the package using the manager
- Select
Search Package URLand typegit@github.com:awareframework/com.awareframework.ios.sensor.activityrecognition.git
- Select
-
Import the package into your target.
- To install it, simply add the following line to your Podfile:
pod 'com.awareframework.ios.sensor.activityrecognition'- com_awareframework_ios_sensor_activityrecognition library into your source code.
import com_awareframework_ios_sensor_activityrecognition- Add a description of
NSMotionUsageDescriptioninto Info.plist
init(config:ActivityRecognitionSensor.Config?): Initializes the activity recognition sensor with the optional configuration.start(): Starts the activity recognition sensor with the optional configuration.stop(): Stops the service.
Class to hold the configuration of the sensor.
sensorObserver: ActivityRecognitionObserver: Callback for live data updates.interval: Int: Data sampling interval in minute. (default = 10)enabled: BooleanSensor is enabled or not. (default =false)debug: Booleanenable/disable logging toLogcat. (default =false)label: StringLabel for the data. (default = "")deviceId: StringId of the device that will be associated with the events and the sensor. (default = "")dbEncryptionKey: StringEncryption key for the database. (default =null)dbType: EngineWhich db engine to use for saving data. (default =Engine.DatabaseType.NONE)dbPath: StringPath of the database. (default = "aware_activityrecognition")dbHost: StringHost for syncing the database. (default =null)
ActivityRecognitionSensor.ACTION_AWARE_ACTIVITYRECOGNITIONfired when accelerometer saved data to db after the period ends.
ActivityRecognitionSensor.ACTION_AWARE_ACTIVITYRECOGNITION_START: received broadcast to start the sensor.ActivityRecognitionSensor.ACTION_AWARE_ACTIVITYRECOGNITION_STOP: received broadcast to stop the sensor.ActivityRecognitionSensor.ACTION_AWARE_ACTIVITYRECOGNITION_SYNC: received broadcast to send sync attempt to the host.ActivityRecognitionSensor.ACTION_AWARE_ACTIVITYRECOGNITION_SET_LABEL: received broadcast to set the data label. Label is expected in theActivityRecognitionSensor.EXTRA_LABELfield of the intent extras.
Contains the raw sensor data.
| Field | Type | Description |
|---|---|---|
| activities | String | The detected activities' name |
| confidence | Int | The confidence that the motion data is accurate. (0=low, 1=medium, 2=high) |
| stationary | Bool | A Boolean indicating whether the device is stationary. |
| walking | String | A Boolean indicating whether the device is on a walking person. |
| running | String | A Boolean indicating whether the device is on a running person. |
| automotive | String | A Boolean indicating whether the device is in an automobile. |
| cycling | String | A Boolean indicating whether the device is in a bicycle. |
| unknown | String | A Boolean indicating whether the type of motion is unknown. |
| label | String | Customizable label. Useful for data calibration or traceability |
| deviceId | String | AWARE device UUID |
| label | String | Customizable label. Useful for data calibration or traceability |
| timestamp | Int64 | Unixtime milliseconds since 1970 |
| timezone | Int | Timezone of the device |
| os | String | Operating system of the device (ex. ios) |
let activitySensor = ActivityRecognitionSensor.init(ActivityRecognitionSensor.Config().apply{config in
config.debug = true
config.interval = 15
config.dbType = .REALM
config.sensorObserver = Observer()
})
activitySensor.start()class Observer:ActivityRecognitionObserver {
func onActivityChanged(data: Array<ActivityRecognitionData>) {
// Your code here ..
}
}Yuuki Nishiyama, yuuki.nishiyama@oulu.fi
Copyright (c) 2021 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.