AWARE: Open Weather
The Open Weather plugin allows us to collect weather information based on your location. The weather data comes from Open Weather API. For using the API, you need to prepare your API KEY on https://openweathermap.org/api.
需求
iOS 10 或更高版本
安装
com.awareframework.ios.sensor.openweather 通过 CocoaPods 提供。
- 要安装它,只需将以下行添加到您的 Podfile 中
pod 'com.awareframework.ios.sensor.openweather'
- 并将com_aware_ios_sensor_openweather库添加到您的源代码中。
import com_awareframework_ios_sensor_openweather
公共函数
OpenWeatherSensor
init(config:OpenWeatherSensor.Config?)
: 使用可选配置初始化开放天气传感器。start()
: 带有可选配置的启动开放天气传感器。stop()
: 停止服务。
OpenWeatherSensor.Config
用于存储传感器配置的类。
字段
sensorObserver: OpenWeatherObserver
: 实时数据更新的回调。
interval: Int
: 获取天气信息的频率(以分钟计),(默认 = 60)units: String
: 英制或公制(默认 = "metric")apiKey: String
: OpenWeather API密钥。从 openweathermap.org 获得免费的API密钥(默认 =null
)
enabled: Boolean
传感器是否启用。 (默认 =false
)debug: Boolean
启用/禁用向Xcode控制台记录日志。(默认 =false
)label: String
数据的标签。 (默认 = "")deviceId: String
将与事件和传感器相关联的设备ID。 (默认 = "")dbEncryptionKey
数据库的加密密钥。 (默认 =null
)dbType: Engine
用于存储数据的数据库引擎。(默认 =Engine.DatabaseType.NONE
)dbPath: String
数据库路径。 (默认 = "aware_openweather")dbHost: String
同步数据库的宿主。 (默认 =null
)
广播
已触发的广播
OpenWeatherSensor.ACTION_AWARE_OPENWEATHER
在周期结束后,当陀螺仪将数据保存到数据库时触发。
已接收广播
OpenWeatherSensor.ACTION_AWARE_OPENWEATHER_START
:接收到启动传感器的广播。OpenWeatherSensor.ACTION_AWARE_OPENWEATHER_STOP
:接收到停止传感器的广播。OpenWeatherSensor.ACTION_AWARE_OPENWEATHER_SYNC
:接收到发送同步尝试到主机的广播。OpenWeatherSensor.ACTION_AWARE_OPENWEATHER_SET_LABEL
:接收到设置数据标签的广播。标签期望在 intent extras 的OpenWeatherSensor.EXTRA_LABEL
字段中。
数据表示
OpenWeather 数据
包含原始传感器数据。
字段 | 类型 | 描述 |
---|---|---|
city | String | 天气的城市 |
temperature | Double | 当前大气温度 |
temperatureMax | Double | 预报最高温度 |
temperatureMin | Double | 预报最低温度 |
unit | String | 计量单位(公制,英制) |
humidity | Double | 预报湿度百分比 |
pressure | Double | 大气压力 |
windSpeed | Double | m/s中的风速 |
windDegrees | Double | 风向 |
cloudiness | Double | 天空中的云量百分比 |
rain | Double | 过去一小时的雨量,以毫米为单位 |
snow | Double | 过去一小时的雪量,以毫米为单位 |
sunrise | Double | 日出时间戳 |
sunset | Double | 日落时间戳 |
weatherIconId | Int | 来自 OpenWeather 的图标 ID |
weatherDescription | String | 预报描述 |
label | String | 可自定义的标签。用于数据校准或追踪 |
deviceId | String | AWARE 设备 UUID |
label | String | 可自定义的标签。用于数据校准或追踪 |
timestamp | Int64 | 自 1970 年以来的 Unixtime 毫秒时间戳 |
timezone | Int | 设备的原始时区偏移量 |
os | String | 设备的操作系统(例如,ios) |
示例用法
openWeather = OpenWeatherSensor.init(OpenWeatherSensor.Config().apply{config in
config.interval = 15 // 15min
config.apiKey = "YOUR_API_KEY"
config.sensorObserver = Observer()
})
openWeather?.start()
class Observer:OpenWeatherObserver{
func onDataChanged(data: OpenWeatherData) {
// Your code here
}
}
作者
Yuuki Nishiyama, [email protected]
许可证
版权所有 (c) 2021 AWARE 移动上下文仪器中间件/框架 (http://www.awareframework.com)
根据Apache许可证版本2.0授权;除非遵守许可证规定或书面同意,否则不得使用此文件。您可以在以下位置获得许可证副本:
https://apache.ac.cn/licenses/LICENSE2.0 除非法律要求或书面同意,否则在许可证下分发的软件按“原样”提供,不提供任何明示或暗示的担保或条件。有关许可证对许可和限制的具体规定,请参阅许可证。