设备离线

更新时间:2024-10-10 07:48:08下载pdf

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

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

接口说明

- (void)getOfflineReminderSupportStatusWithSuccess:(nullable ThingSuccessBOOL)success failure:(nullable ThingFailureError)failure;

参数说明

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

示例代码

Objc:

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

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

Swift:

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

返回设备离线告警状态

接口说明

- (void)getOfflineReminderStatusWithSuccess:(nullable ThingSuccessBOOL)success failure:(nullable ThingFailureError)failure;

参数说明

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

示例代码

Objc:

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

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

Swift:

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

设置设备离线告警状态

接口说明

- (void)setOfflineReminderStatus:(BOOL)status success:(nullable ThingSuccessBOOL)success failure:(nullable ThingFailureError)failure;

参数说明

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

示例代码

Objc:

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

    [self.device setOfflineReminderStatus:status success:^(BOOL result) {
        NSLog(@"Set offline reminder status: %d", result);
    } failure:^(NSError *error) {
        NSLog(@"Failed to set offline reminder status: %@", 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("Failed to set offline reminder status: \(e)")
        }
    })
}