AWAREFramework
AWARE 是专注于收集、推断、记录和共享移动设备上下文信息的 iOS 和 Android 框架,适用于应用开发者、研究人员和智能手机用户。AWARE 捕获基于设备、软件和人类的 ESM 数据。它们将数据转换成您能理解的信息。
支持的和扩展的传感器
默认传感器
- 加速度计
- 陀螺仪
- 磁力计
- 重力
- 旋转
- 位置
- 气压计
- 电池
- 网络
- 电话
- 处理器
- 接近度
- 时区
- Wi-Fi
- 屏幕事件
- Fitbit
Google 登录- 内存
- NTPTime
- OpenWeatherMap
- 耳机运动(iOS 14 或更高版本)
扩展
以下传感器可以在扩展程序中使用,因为这些传感器需要额外的权限进入Info.plist,并由苹果审核。您可以从这里获取详细信息。
- 运动活动
- 计步器
- 蓝牙
- 心率(BLE)
- 麦克风(环境噪声)
- 日历
- 联系人
- HealthKit
安装
0.(选项)使用Rosetta打开Xcode以在模拟器上运行已开发的程序
如果您可以使用物理设备开发应用程序,则可以跳过此步骤。
1. 安装AWAREFramework-iOS
AWAREFramework-iOS可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'AWAREFramework', '~> 1.14.2'
并在Xcode项目中运行pod install
。
2. 编辑配置
为了在后台收集数据,您需要按照如下方式编辑项目中的 Info.plist
和 Capabilities/Background Modes
。
[注意] 以下设置是一个最小条件,如果您使用特殊传感器(例如,环境噪音、HealthKit、活动识别等),可能需要更多修改。请参考链接了解配置信息。
2-1. Info.plist
- 隐私 - 总是和在使用时使用位置 Usage Description
- 隐私 - 在使用时使用位置 Usage Description
- 隐私 - 总是使用位置 Usage Description
2-2. Capabilities/Background Modes
3. 请求权限并激活 AWAREFramework
要在项目中使用 AWAREFramework,您需要(1)将 AWAREFramework
导入到您的类中,并且(2)请求访问 iOS 位置传感器始终的权限。权限批准后,您可以(3)激活 AWARECore
。 (4)AWARECore
、AWAREStudy
和 AWARESensorManager
是管理库中传感/synchronization 调度的单例实例。您可以通过 How To Use 会话中描述的方式控制任何传感器。
我们建议您在《AppDelegate》中的-application:didFinishLaunchingWithOptions:launchOptions:
方法中激活AWARECore
,这个方法在应用程序启动时只会被调用一次。
/// AppDelegate.swift ///
import UIKit
import AWAREFramework /// (1) import `AWAREFramework` into your source code.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
////////////////////////
let core = AWARECore.shared()
let study = AWAREStudy.shared()
let manager = AWARESensorManager.shared()
/// (2) request permissions
core.requestPermissionForBackgroundSensing{ (status) in
core.requestPermissionForPushNotification(completion:nil)
/// (3) activate AWARECore
core.activate()
/// (4) use sensors
/// EDIT HERE ///
}
////////////////////////
return true
}
}
如何使用
示例 1:初始化传感器并将传感器数据保存到本地数据库
只需以下代码即可让您的应用程序收集后台传感器数据。数据将保存在本地存储中。
/// Example1 (Swift): Accelerometer ///
let accelerometer = Accelerometer()
accelerometer.setSensorEventHandler { (sensor, data) in
print(data)
}
accelerometer.startSensor()
manager.add(accelerometer)
示例 2:同步本地数据库和 AWARE 服务器
AWAREFramework-iOS 允许我们通过向 AWAREStudy 添加服务器网址来同步应用程序和 AWARE 服务器。有关 AWARE 服务器,请访问我们的网站。
/// Example2 (Swift): Accelerometer + AWARE Server ///
study.setStudyURL("https://api.awareframework.com/index.php/webservice/index/STUDY_ID/PASS")
let accelerometer = Accelerometer(awareStudy: study)
accelerometer.startSensor()
accelerometer.startSyncDB()
// or
manager.add(accelerometer)
示例 3:在 AWARE 仪表板上应用设置
此外,这个库允许我们使用-joinStuyWithURL:completion
方法在 AWARE 仪表板上应用设置。
/// Example3 (Swift): AWARE Dashboard ////
let url = "https://api.awareframework.com/index.php/webservice/index/STUDY_ID/PASS"
study.join(withURL: url, completion: { (settings, studyState, error) in
manager.addSensors(with: study)
manager.startAllSensors()
})
经验抽样方法 (ESM)
该库支持 ESM。该方法允许我们在应用中特定时间提出问题。以下代码示例显示了每天在 9:00、12:00、18:00 和 21:00 显示单选题。请访问我们的网站了解有关 ESM 的更多信息。
/// Swift ///
let schdule = ESMSchedule()
schdule.notificationTitle = "notification title"
schdule.notificationBody = "notification body"
schdule.scheduleId = "schedule_id"
schdule.expirationThreshold = 60
schdule.startDate = Date.init()
schdule.endDate = Date.init(timeIntervalSinceNow: 60*60*24*10)
schdule.fireHours = [9,12,18,21]
let radio = ESMItem(asRadioESMWithTrigger: "1_radio", radioItems: ["A","B","C","D","E"])
radio.setTitle("ESM title")
radio.setInstructions("some instructions")
schdule.addESM(radio)
let esmManager = ESMScheduleManager.shared()
// esmManager.removeAllNotifications()
// esmManager.removeAllESMHitoryFromDB()
// esmManager.removeAllSchedulesFromDB()
esmManager.add(schdule)
请调用以下代码块来显示 ESMScrollViewController
(例如,在 -viewDidAppear:
)。
/// Swift ///
let schedules = ESMScheduleManager.shared().getValidSchedules() {
if(schedules.count > 0){
let esmViewController = ESMScrollViewController()
self.present(esmViewController, animated: true){}
}
支持的 ESM 类型
该库支持 16 种 ESM 类型。您可以通过 此链接查看截图。
- 文本
- 单选
- 复选框
- 李克特量表
- 快速回答
- 量表
- 日期时间
- 感知焦虑量表
- 数字
- 网页
- 日期
- 时间
- 时钟
- 图片
- 音频
- 视频
示例应用程序
我们提供了一些示例应用程序。您可以参考或修改这些应用程序以供您使用。
- RichClient (aware-client-ios-v2)
- SensingApp
- SimpleClient
- DynamicESM
- ScheduleESM
- CustomESM
- CustomSensor
- Visualizer
作者
西山祐希 [email protected]
引用
如果该库有助于您的研究,请在您的研究出版物中引用以下论文。
@InProceedings{aware_ios,
author={Nishiyama, Yuuki and Ferreira, Denzil and Eigen, Yusaku and Sasaki, Wataru and Okoshi, Tadashi and Nakazawa, Jin and Dey, Anind K. and Sezaki, Kaoru},
title={IOS Crowd--Sensing Won't Hurt a Bit!: AWARE Framework and Sustainable Study Guideline for iOS Platform},
booktitle={Distributed, Ambient and Pervasive Interactions},
year={2020},
pages={223--243},
isbn={978-3-030-50344-4},
doi={10.1007/978-3-030-50344-4_17},
}
@inproceedings{aware_ios_in_the_wild,
author = {Nishiyama, Yuuki and Ferreira, Denzil and Sasaki, Wataru and Okoshi, Tadashi and Nakazawa, Jin and Dey, Anind K. and Sezaki, Kaoru},
title = {Using IOS for Inconspicuous Data Collection: A Real-World Assessment},
year = {2020},
doi = {10.1145/3410530.3414369},
booktitle = {Adjunct Proceedings of the 2020 ACM International Joint Conference on Pervasive and Ubiquitous Computing and Proceedings of the 2020 ACM International Symposium on Wearable Computers},
pages = {261–266},
numpages = {6},
series = {UbiComp-ISWC '20}
}
许可证
AWAREFramework 采用 Apache2 许可证。有关更多信息,请参阅 LICENSE 文件。