消息相关功能

更新时间:2024-06-07 08:55:18下载pdf

查询消息列表

接口说明

- (void)fetchMessageListWithListRequestModel:(ThingSmartMessageListRequestModel *)listRequestModel
                                     success:(void (^)(NSArray<ThingSmartMessageListModel *> *messageList))success
                                     failure:(ThingFailureError)failure;

参数说明

参数 说明
listRequestModel 消息列表请求模型
success 成功回调,返回消息数组
failure 失败回调,返回失败原因

ThingSmartMessageListRequestModel数据模型

字段 说明
msgType 消息类型:
  • ThingMessageTypeAlarm:告警消息
  • ThingMessageTypeFamily:家庭消息
  • ThingMessageTypeNotice:通知消息
limit 消息列表的最大请求数量
offset 已请求的消息列表总量

示例代码

Objective-C:

ThingSmartMessageListRequestModel *requestModel = [[ThingSmartMessageListRequestModel alloc] init];
requestModel.msgType = ThingMessageTypeAlarm;
requestModel.offset = 0;
requestModel.limit = 15;

ThingSmartMessage *message = [[ThingSmartMessage alloc] init];
[message fetchMessageListWithListRequestModel:requestModel success:^(NSArray<ThingSmartMessageListModel *> * _Nonnull messageList) {

 } failure:^(NSError *error) {

 }];

Swift:

let requesModel = ThingSmartMessageListRequestModel()
requesModel.msgType = .alarm
requesModel.limit = 15
requesModel.offset = 0

let message = ThingSmartMessage()
message.fetchList(with: requesModel) { list in

} failure: { error in

}

查询消息详情列表

接口说明

- (void)fetchEncryptMessageDetailListWithListRequestModel:(ThingSmartMessageDetailListRequestModel *)detailListRequestModel
                                                  success:(void (^)(NSArray<ThingSmartMessageListModel *> *messageList))success
                                                  failure:(ThingFailureError)failure;

参数说明

参数 说明
detailListRequestModel 消息详情请求模型
success 成功回调,返回消息详情数组
failure 失败回调,返回失败原因

ThingSmartMessageDetailListRequestModel数据模型

字段 说明
msgType 消息类型, 仅支持告警消息ThingMessageTypeAlarm
limit 详情列表的最大请求数量
offset 已请求的详情列表总量
msgSrcId 发送告警消息的设备 ID

示例代码

Objective-C:

ThingSmartMessageDetailListRequestModel *listRequestModel = [[ThingSmartMessageDetailListRequestModel alloc] init];
listRequestModel.msgType = ThingMessageTypeAlarm;
listRequestModel.limit = 15;
listRequestModel.offset = 0;
listRequestModel.msgSrcId = @"xxx";

ThingSmartMessage *message = [[ThingSmartMessage alloc] init];
[message fetchEncryptMessageDetailListWithListRequestModel:listRequestModel success:^(NSArray<ThingSmartMessageListModel *> * _Nonnull messageList) {

} failure:^(NSError *error) {

}];

Swift:

let requesModel = ThingSmartMessageDetailListRequestModel()
requesModel.msgType = .alarm
requesModel.limit = 15
requesModel.offset = 0
requesModel.msgSrcId = ""

let message = ThingSmartMessage()
message.fetchEncryptMessageDetailList(with: requesModel) { list in

} failure: { error in

}

查询消息详情秘钥

接口说明

- (void)fetchMessageDecryptKeyWithEncryptRequestModel:(NSArray<ThingSmartMessageEncryptRequestModel *> *)encryptRequestListModel
                                              success:(void (^)(NSArray<ThingSmartMessageDecryptModel *> *messageList))success
                                              failure:(ThingFailureError)failure;

参数说明

参数 说明
encryptRequestListModel 消息秘钥请求模型数组
success 成功回调,返回消息秘钥数组
failure 失败回调,返回失败原因

ThingSmartMessageEncryptRequestModel数据模型

字段 说明
businessNo 消息 ID
deviceId 发送告警消息的设备 ID
homeId 家庭 ID
time 消息时间戳

ThingSmartMessageDecryptModel数据模型

字段 说明
businessNo 消息 ID
businessKey 消息秘钥

示例代码

Objective-C:

ThingSmartMessageEncryptRequestModel *requestModel = [[ThingSmartMessageEncryptRequestModel alloc] init];
requestModel.businessNo = message.msgId;
requestModel.deviceId = message.msgSrcId;
requestModel.time = message.time;
requestModel.homeId = message.homeID;

ThingSmartMessage *message = [[ThingSmartMessage alloc] init];
[messagefetchMessageDecryptKeyWithEncryptRequestModel:@[requestModel] success:^(NSArray<ThingSmartMessageDecryptModel *> * _Nonnull decryptList) {

} failure:^(NSError *error) {

}];

Swift:

let requesModel = ThingSmartMessageEncryptRequestModel()
requestModel.businessNo = message.msgId
requestModel.deviceId = message.msgSrcId
requestModel.time = message.time
requestModel.homeId = message.homeID

let message = ThingSmartMessage()
message.fetchDecryptKey(withEncryptRequestModel: [requesModel]) { list in

} failure: { error in

}

批量删除消息

接口说明

- (void)deleteMessageWithDeleteRequestModel:(ThingSmartMessageListDeleteRequestModel *)deleteRequestModel
                                    success:(ThingSuccessBOOL)success
                                    failure:(ThingFailureError)failure;

参数说明

参数 说明
deleteRequestModel 删除消息请求模型
success 成功回调
failure 失败回调,返回失败原因

ThingSmartMessageListDeleteRequestModel数据模型

字段 说明
msgType 消息类型:
  • ThingMessageTypeAlarm:告警消息
  • ThingMessageTypeFamily:家庭消息
  • ThingMessageTypeNotice:通知消息
msgIds 待删除的消息列表
msgSrcId 待删除的告警消息列表
  • 如需删除告警消息 列表 中的消息,请设置参数 msgSrcIds
  • 如需删除告警消息 详情列表 中的消息,请设置参数 ids
  • 如需删除家庭消息、通知消息 列表 中的消息,请设置参数msgIds

不可以同时设置 msgSrcIdsids 参数,否则 详情列表 中的消息将无法被删除。

示例代码

Objective-C:

ThingSmartMessageListDeleteRequestModel *requestModel = [[ThingSmartMessageListDeleteRequestModel alloc] init];
requestModel.msgType = ThingMessageTypeAlarm;
requestModel.msgSrcIds = @[@"xx", @"xx"];

ThingSmartMessage *message = [[ThingSmartMessage alloc] init];
[message deleteMessageWithDeleteRequestModel:requestModel success:^(BOOL result) {

} failure:^(NSError *error) {

}];

Swift:

let requesModel = ThingSmartMessageListDeleteRequestModel()
requesModel.msgType = .alarm
requesModel.msgSrcIds = ["xx", "xx"]

let message = ThingSmartMessage()
message.delete(with: requesModel) { result in

} failure: { error in

}

检查新消息

接口说明

- (void)getLatestMessageWithSuccess:(ThingSuccessDict)success failure:(ThingFailureError)failure

参数说明

参数 说明
success 成功回调,返回字典类型,包含的字典 Key 有:
  • alarm:告警消息
  • family:家庭消息
  • notification:通知消息
failure 失败回调,返回失败原因

请求不同的 ThingSmartMessageListRequestModelmsgType 会有不同新消息判断逻辑。

  • 对于家庭消息和通知消息,当有新消息时,调用 getLatestMessageWithSuccess:failure: 后会返回 true。在调用 查询消息列表 之后,再次调用 getLatestMessageWithSuccess:failure: 时,状态结果将被置为 false

  • 对于告警消息,当调用 readMessageWithReadRequestModel:success:failure: 后,再调用 查询消息列表 时,ThingSmartMessageListModelhasNotRead 字段会被置为 false

示例代码

Objective-C:

//      self.smartMessage = [[ThingSmartMessage alloc] init];
    [self.smartMessage getLatestMessageWithSuccess:^(NSDictionary *result) {
        NSLog(@"get latesMessage success:%@", result);
    } failure:^(NSError *error) {
        NSLog(@"get message max time failure:%@", error);
    }];

Swift:

    smartMessage?.getLatestMessageWithSuccess({ (result) in
        print("get message max time success :\(result)")
    }, failure: { (error) in
        if let e = error {
            print("get message max time failure: \(e)")
        }
    })

设置消息已读

接口说明

- (void)readMessageWithReadRequestModel:(ThingSmartMessageListReadRequestModel *)readRequestModel
                                success:(ThingSuccessBOOL)success
                                failure:(ThingFailureError)failure;

参数说明

参数 说明
readRequestModel 已读消息请求模型
success 成功回调
failure 失败回调,返回失败原因

ThingSmartMessageListReadRequestModel数据模型

字段 说明
msgType 消息类型,仅支持告警消息ThingMessageTypeAlarm
msgIds 已读消息列表

示例代码

Objective-C:

ThingSmartMessageListReadRequestModel *requestModel = [[ThingSmartMessageListReadRequestModel alloc] init];
requestModel.msgType = ThingMessageTypeAlarm;
requestModel.msgIds = @[@"xx", @"xx"];

ThingSmartMessage *message = [[ThingSmartMessage alloc] init];
[message readMessageWithReadRequestModel:requestModel success:^(BOOL result) {

} failure:^(NSError *error) {

}];

Swift:

let requesModel = ThingSmartMessageListReadRequestModel()
requesModel.msgType = .alarm
requesModel.msgIds = ["xx", "xx"]

let message = ThingSmartMessage()
message.read(with: requesModel) { result in

} failure: { error in

}