com.awareframework.ios.sensor.ibeacon 0.6.0

com.awareframework.ios.sensor.ibeacon 0.6.0

tetujinyuuki.nishiyama 维护。



  • Yuuki Nishiyama

com.awareframework.ios.sensor.ibeacon

CI Status Version License Platform

要求

iOS 10 或更高版本

安装

NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription 键添加到 Info.plist 中

如果您需要为信标启用持久的后台定位,则需要激活应用中的 后台模式功能(位置更新)

com.aware.ios.sensor.ibeacon 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod 'com.awareframework.ios.sensor.ibeacon'

将 com.awareframework.ios.sensor.ibeacon 库导入到您的源代码中。

import com_awareframework_ios_sensor_ibeacon

公共函数

IBeaconSensor

  • init(config:ibeaconSensor.Config?) : 初始化IBeacon传感器,可带可选配置。
  • start(): 使用可选配置启动IBeacon传感器。
  • stop(): 停止服务。

IBeaconSensor.Config

存储传感器配置的类。

Fields

  • regions: Array<CLBeaconRegion> 用于检测蓝牙信标的区域。
  • sensorObserver: IBeaconObserver? 用于监测传感器事件的传感器观察者
  • enabled: Boolean 传感器是否启用。 (默认 = false)
  • debug: Boolean 开启/关闭向 Logcat 记录日志。 (默认 = false)
  • label: String 数据的标签。 (默认 = "")
  • deviceId: String 事件和传感器相关联的设备ID。 (默认 = "")
  • dbEncryptionKey 数据库的加密密钥。 (默认 = null)
  • dbType: Engine 用于保存数据的数据库引擎。 (默认 = Engine.DatabaseType.NONE)
  • dbPath: String 数据库的路径。 (默认 = "aware_ibeacon")
  • dbHost: String 数据库同步的主机。 (默认 = null)

Broadcasts

Fired Broadcasts

  • IBeaconSensor.ACTION_AWARE_IBEACON 当ibeacon在指定周期结束时将数据保存到数据库时触发。

接收到的广播

  • IBeaconSensor.ACTION_AWARE_IBEACON_START:收到广播以启动传感器。
  • IBeaconSensor.ACTION_AWARE_IBEACON_STOP:收到广播以停止传感器。
  • IBeaconSensor.ACTION_AWARE_IBEACON_SYNC:收到广播以向主机发送同步尝试。
  • IBeaconSensor.ACTION_AWARE_IBEACON_SET_LABEL:收到广播以设置数据标签。标签预期位于intent extras的IBeaconSensor.EXTRA_LABEL字段中。

数据表示

iBeacon数据

包含原始传感器数据。

字段 类型 描述
uuid 字符串 被目标标志的唯一ID。
major Int16 识别一组标志的值。(16位)
minor Int16 识别组内特定标志的值。(16位)
rssi Int 标志的接收信号强度,以分贝为单位。
identifier 字符串 标志的标识符。
proximity Int 与标志的相对距离。(0=未知,1=立即,2=近,3=远)
accuracy Double 相对距离值的精度,从标志处 measure in meters。
label 字符串 可定制标签。用于数据校准或可追溯性很有用
deviceId 字符串 AWARE设备UUID
label 字符串 可定制标签。用于数据校准或可追溯性很有用
timestamp Int64 1970年以来的Unixtime毫秒数
timezone Int 设备的时区
os 字符串 设备的操作系统(例如:android)

iBeacon区域状态数据

字段 类型 描述
identifier 字符串 标志的标识符。
state Int 设备相对于区域的当前状态。(0=未知,1=内部,2=外部)
label 字符串 可定制标签。用于数据校准或可追溯性很有用
deviceId 字符串 AWARE设备UUID
label 字符串 可定制标签。用于数据校准或可追溯性很有用
timestamp Int64 1970年以来的Unixtime毫秒数
timezone Int 设备的时区
os 字符串 设备的操作系统(例如:android)

iBeacon区域事件数据

字段 类型 描述
identifier 字符串 标志的标识符。
state Int 区域进入和退出事件(0=退出,1=进入)
label 字符串 可定制标签。用于数据校准或可追溯性很有用
deviceId 字符串 AWARE设备UUID
label 字符串 可定制标签。用于数据校准或可追溯性很有用
timestamp Int64 1970年以来的Unixtime毫秒数
timezone Int 设备的时区
os 字符串 设备的操作系统(例如:android)

示例用法

将ibeacon传感器库(com_aware_ios_sensor_ibeacon)导入目标类中。

import com_awareframework_ios_sensor_ibeacon

生成ibeacon传感器实例并启动/停止传感器。

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, [email protected]

相关链接

许可证

版权所有(c)2021 AWARE移动上下文测量中间件/框架(http://www.awareframework.com

根据Apache License 2.0(“许可证”)许可;除非符合许可证规定或以书面形式同意,否则不得使用此文件。您可以在以下位置获得许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0 除非法律要求或经书面同意,否则在许可证下分发的软件按“原样”分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言、权限和限制,请参阅许可证。