【开发资料】设备离线提醒功能开发
Posted: 2024年 Apr 1日 19:11
用途
当设备离线超过30分钟时(低功耗设备8个小时),手机推送中心
和 app消息中心
都将收到离线提醒的消息。
接入
要求:需要接入UI业务包5.8.0及以上版本
Code: Select all
source 'https://github.com/tuya/tuya-pod-specs.git'
platform :ios, '11.0'
target 'Your_Project_Name' do
pod "ThingSmartBusinessExtensionKit"
end
API 说明
- 判断设备是否支持离线提醒功能
入参 | 类型 | 说明 |
---|---|---|
deviceId | string | 设备id |
success | block | 成功回调 |
failure | block | 失败回调 |
Code: Select all
/// get the offline reminder support status of device
/// - Parameters:
/// - deviceId: the id of the device
/// - success: support if status is true, otherwise not support
/// - failure: error happen
class func getOfflineReminderSupportStatus( withDeviceId deviceId: String, success: @escaping (Bool) -> Void, failure: @escaping (Error) -> Void)
- 获取设备当前的离线提醒状态
入参 | 类型 | 说明 |
---|---|---|
deviceId | string | 设备id |
success | block | 成功回调 |
failure | block | 失败回调 |
Code: Select all
/// get the offline reminder status of device
/// - Parameters:
/// - deviceId: the id of the device
/// - success: open if status is true, otherwise close
/// - failure: error happen
class func getOfflineReminderStatus(withDeviceId deviceId: String, success: @escaping (Bool) -> Void, failure: @escaping (Error) -> Void)
- 更新设备的离线提醒状态
入参 | 类型 | 说明 |
---|---|---|
deviceId | string | 设备id |
status | bool | 打开为true,关闭为false |
success | block | 成功回调 |
failure | block | 失败回调 |
Code: Select all
/// update the offline reminder status of device
/// - Parameters:
/// - deviceId: the id of the device
/// - status: the offline reminder status
/// - success: update success
/// - failure: error happen
class func updateOfflineReminderStatus(withDeviceId deviceId: String, status: Bool, success: @escaping () -> Void, failure: @escaping (Error) -> Void)
使用示例
Code: Select all
class DeviceOfflineReminderVC: UIViewController {
var deviceId: String
lazy var label: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.textColor = UIColor.green
return label
}()
lazy var statusSwitch: UISwitch = {
let statusSwitch = UISwitch(frame: CGRectZero)
statusSwitch.addTarget(self, action: #selector(change(sender:)), for: .valueChanged)
return statusSwitch
}()
init(deviceId: String) {
self.deviceId = deviceId
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.label)
self.view.addSubview(self.statusSwitch)
self.label.frame = CGRect(x: 20, y: 100, width: 150, height: 27)
self.statusSwitch.frame = CGRect(x: 170, y: 100, width: 0, height: 0)
self.statusSwitch.isHidden = true
self.loadData()
}
func loadData() {
SVProgressHUD.show()
ThingDeviceOfflineReminderManager.getOfflineReminderSupportStatus(withDeviceId: self.deviceId) { support in
if (support) {
ThingDeviceOfflineReminderManager.getOfflineReminderStatus(withDeviceId: self.deviceId) { status in
SVProgressHUD.dismiss()
self.label.text = "支持"
self.statusSwitch.isHidden = false
self.statusSwitch.isOn = status
} failure: { e in
SVProgressHUD.dismiss()
self.label.text = "支持"
self.statusSwitch.isHidden = false
self.statusSwitch.isOn = false
}
}else{
SVProgressHUD.dismiss()
self.label.text = "不支持"
self.statusSwitch.isHidden = true
}
} failure: { e in
SVProgressHUD.dismiss()
}
}
@objc func change(sender: UISwitch) {
ThingDeviceOfflineReminderManager.updateOfflineReminderStatus(withDeviceId: self.deviceId, status: sender.isOn) {
} failure: { e in
}
}
}
demo下载地址:https://github.com/tuya/tuya-home-ios-sdk-sample-swift