Skip to content

Latest commit

 

History

History
118 lines (84 loc) · 6.07 KB

File metadata and controls

118 lines (84 loc) · 6.07 KB

AWARE: Activity Recognition

Swift Package Manager compatible

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.

Requirements

iOS 13 or later

Installation

Add the package with Swift Package Manager:

  • Package URL: https://github.com/awareframework/com.awareframework.ios.sensor.activityrecognition.git
  • Product: com.awareframework.ios.sensor.activityrecognition
  • Module: import com_awareframework_ios_sensor_activityrecognition

See the core package README for the Xcode, Package.swift and command-line installation steps.

Info.plist: NSMotionUsageDescription.

Public Functions

ActivityRecognitionSensor

  • 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.

ActivityRecognitionSensor.Config

Class to hold the configuration of the sensor.

Fields

  • sensorObserver: ActivityRecognitionObserver: Callback for live data updates.
  • sampleIntervalSeconds: Int: Data sampling interval in seconds. (default = 600)
  • enabled: Bool: Sensor is enabled or not. (default = false)
  • debug: Bool: Enable/disable logging. (default = false)
  • label: String: Label for the data. (default = "")
  • deviceId: String: Id of the device that will be associated with the events and the sensor. (default = "")
  • dbEncryptionKey: String: Encryption key for the database. (default = nil)
  • dbType: DatabaseType: Which db engine to use for saving data. (default = .none)
  • dbPath: String: Path of the database. (default = "aware_activityrecognition")
  • dbHost: String?: Host for syncing the database. (default = nil)

Broadcasts

Fired Broadcasts

  • ActivityRecognitionSensor.ACTION_AWARE_ACTIVITYRECOGNITION: fired when activity recognition data is saved to db after the sample interval ends.

Received Broadcasts

  • 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 the ActivityRecognitionSensor.EXTRA_LABEL field of the intent extras.

Data Representations

Activity Recognition Data

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 Bool A Boolean indicating whether the device is on a walking person.
running Bool A Boolean indicating whether the device is on a running person.
automotive Bool A Boolean indicating whether the device is in an automobile.
cycling Bool A Boolean indicating whether the device is in a bicycle.
unknown Bool 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
timestamp Int64 Unixtime milliseconds since 1970
timezone Int Timezone of the device
os String Operating system of the device (ex. ios)
jsonVersion Int JSON schema version

Example Usage

let activitySensor = ActivityRecognitionSensor.init(ActivityRecognitionSensor.Config().apply { config in
    config.debug = true
    config.sampleIntervalSeconds = 900
    config.dbType = .sqlite
    config.sensorObserver = Observer()
})
activitySensor.start()
class Observer:ActivityRecognitionObserver {
    func onActivityChanged(data: Array<ActivityRecognitionData>) {
        // Your code here ..
    }
}

Author

Yuuki Nishiyama, [email protected]

Related Links

License

Copyright (c) 2025 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.