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.ibeacon.git
- Select
-
Import the package into your target.
com.aware.ios.sensor.ibeacon is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'com.awareframework.ios.sensor.ibeacon'Add NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription keys into Info.plist
If you need persistent background ranging for beacons, you'll need to activate the Background Modes capability (Location Updates) for your application.
Import com.awareframework.ios.sensor.ibeacon library into your source code.
import com_awareframework_ios_sensor_ibeaconinit(config:ibeaconSensor.Config?): Initializes the IBeacon sensor with the optional configuration.start(): Starts the IBeacon sensor with the optional configuration.stop(): Stops the service.
Class to hold the configuration of the sensor.
regions: Array<CLBeaconRegion>Regions that you use to detect Bluetooth beacons.sensorObserver: IBeaconObserver?A sensor observer for monitoring sensor eventsenabled: 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 = "")dbEncryptionKeyEncryption 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_ibeacon")dbHost: StringHost for syncing the database. (default =null)
IBeaconSensor.ACTION_AWARE_IBEACONfired when ibeacon saved data to db after the period ends.
IBeaconSensor.ACTION_AWARE_IBEACON_START: received broadcast to start the sensor.IBeaconSensor.ACTION_AWARE_IBEACON_STOP: received broadcast to stop the sensor.IBeaconSensor.ACTION_AWARE_IBEACON_SYNC: received broadcast to send sync attempt to the host.IBeaconSensor.ACTION_AWARE_IBEACON_SET_LABEL: received broadcast to set the data label. Label is expected in theIBeaconSensor.EXTRA_LABELfield of the intent extras.
Contains the raw sensor data.
| Field | Type | Description |
|---|---|---|
| uuid | String | The unique ID of the beacons being targeted. |
| major | Int16 | The value identifying a group of beacons. (16bit) |
| minor | Int16 | The value identifying a specific beacon within a group. (16bit) |
| rssi | Int | The received signal strength of the beacon, measured in decibels. |
| identifier | String | The identifer of the beacon. |
| proximity | Int | The relative distance to the beacon. (0=unknown, 1=immediate, 2=near, 3=far) |
| accuracy | Double | The accuracy of the proximity value, measured in meters from the beacon. |
| 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. android) |
| Field | Type | Description |
|---|---|---|
| identifier | String | The identifer of the beacon. |
| state | Int | The current state of the device with reference to a region. (0=unknown, 1= inside, 2=outside) |
| 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. android) |
| Field | Type | Description |
|---|---|---|
| identifier | String | The identifer of the beacon. |
| state | Int | The event of region enter and exit events (0=exit, 1=enter) |
| 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. android) |
Import ibeacon sensor library (com_aware_ios_sensor_ibeacon) to your target class.
import com_awareframework_ios_sensor_ibeaconGenerate an ibeacon sensor instance and start/stop the sensor.
let ibeacon = IBeaconSensor(IBeaconSensor.Config().apply{config in
let uuid = UUID.init(uuidString: "D8219342-6770-4AA4-8075-02E4A10084D9")
let regionA = CLBeaconRegion(proximityUUID:uuid!, identifier: "Test")
config.addRegion(regionA)
config.sensorObserver = Observer()
})
ibeacon?.start()
ibeacon?.stop()class Observer:IBeaconObserver{
func didDetermineState(region: IBeaconRegionStateData) {
// Your code here
}
func didRangeBeacons(beacons: [IBeaconData]) {
// Your code here
}
func didEnterRegion(region: IBeaconRegionEventData) {
// Your code here
}
func didExitRegion(region: IBeaconRegionEventData) {
// Your code here
}
}Yuuki Nishiyama (The University of Tokyo), nishiyama@csis.u-tokyo.ac.jp
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.