离线提醒

更新时间:2024-04-23 07:38:54下载pdf

当普通设备离线超过 30 分钟或者低功耗设备离线超过 8 个小时,手机推送中心App 消息中心 都将收到离线提醒的消息。

接入

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 失败回调
/// get the offline reminder support status of device
/// - Parameters:
///   - deviceId: the ID of the device
///   - success: supported if status is true, otherwise not supported
///   - failure: an error occurs
class func getOfflineReminderSupportStatus( withDeviceId deviceId: String, success: @escaping (Bool) -> Void, failure: @escaping (Error) -> Void)

获取设备当前的离线提醒状态

入参 类型 说明
deviceId string 设备 ID
success block 成功回调
failure block 失败回调
/// get the offline reminder status of device
/// - Parameters:
///   - deviceId: the ID of the device
///   - success: open if status is true, otherwise close
///   - failure: an error occurs
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 失败回调
/// update the offline reminder status of device
/// - Parameters:
///   - deviceId: the ID of the device
///   - status: the offline reminder status
///   - success: update success
///   - failure: an error occurs
class func updateOfflineReminderStatus(withDeviceId deviceId: String, status: Bool, success: @escaping () -> Void, failure: @escaping (Error) -> Void)

调用示例

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 = "support"
                    self.statusSwitch.isHidden = false
                    self.statusSwitch.isOn = status
                } failure: { e in
                    SVProgressHUD.dismiss()
                    self.label.text = "support"
                    self.statusSwitch.isHidden = false
                    self.statusSwitch.isOn = false
                }


            }else{
                SVProgressHUD.dismiss()
                self.label.text = "do not support"
                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

更多信息,参考 Demo