设备离线

更新时间:2023-05-25 06:23:50

设备离线是指设备完成配网后,出现掉线、无网络响应的情况。您可以为设备开启离线告警,发生设备离线的情况后,设备会向指定用户发送通知。用户可以订阅消息推送功能来开启该功能。

检查设备是否支持离线告警

接口说明

- (void)getOfflineReminderSupportStatusWithSuccess:(nullable TYSuccessBOOL)success failure:(nullable TYFailureError)failure;

参数说明

参数 说明
success 获取离线告警成功回调
failure 失败回调

示例代码

Objc:

- (void)getCurrentOfflineReminderSupportStatus {
    // self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

    [self.device getOfflineReminderSupportStatusWithSuccess:^(BOOL result) {
        NSLog(@"get current offline reminder support status: %d", result);
    } failure:^(NSError *error) {
        NSLog(@"get current Wifi Info failure: %@", error);
    }];
}

Swift:

func getCurrentOfflineReminderSupportStatus() {
    device?.getOfflineReminderSupportStatus(success: { status in
        print("get current offline reminder support status: \(status)")
    }, failure: { (error) in
        if let e = error {
          print("get current offline reminder support status failure: \(e)")
        }
    })
}

返回设备离线告警状态

接口说明

- (void)getOfflineReminderStatusWithSuccess:(nullable TYSuccessBOOL)success failure:(nullable TYFailureError)failure;

参数说明

参数 说明
success 获取离线告警状态成功回调
failure 失败回调

示例代码

Objc:

- (void)getCurrentOfflineReminderStatus {
    // self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

    [self.device getOfflineReminderStatusWithSuccess:^(BOOL result) {
        NSLog(@"get current offline reminder status: %d", result);
    } failure:^(NSError *error) {
        NSLog(@"get current Wifi Info failure: %@", error);
    }];
}

Swift:

func getCurrentOfflineReminderStatus() {
    device?.getOfflineReminderStatusWithSuccess(success: { status in
        print("get current offline reminder status: \(status)")
    }, failure: { (error) in
        if let e = error {
          print("get current offline reminder status failure: \(e)")
        }
    })
}

设置设备离线告警状态

接口说明

- (void)setOfflineReminderStatus:(BOOL)status success:(nullable TYSuccessBOOL)success failure:(nullable TYFailureError)failure;

参数说明

参数 说明
status 离线告警状态
success 设置离线告警状态成功回调
failure 失败回调

示例代码

Objc:

- (void)setOfflineReminderStatus:(BOOL)status {
    // self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

    [self.device setOfflineReminderStatus:status success:^(BOOL result) {
        NSLog(@"set Offline Reminder Status: %d", result);
    } failure:^(NSError *error) {
        NSLog(@"set Offline Reminder Status failure: %@", error);
    }];
}

Swift:

func setOfflineReminderStatus(status: Bool) {
    device?.getOfflineReminderStatusWithSuccess(success: { status in
        print("set offline reminder status: \(status)")
    }, failure: { (error) in
        if let e = error {
          print("set offline reminder status failure: \(e)")
        }
    })
}