Last Updated on : 2024-08-22 02:57:17download
This topic introduces how to manage message content.
The ThingSmartBusinessExtensionKit
component offers more features than the ThingSmartMessage
. If you are still using ThingSmartMessage
, please refer to this document.
API description
- (void)fetchMessageListWithListRequestModel:(ThingSmartMessageListRequestModel *)listRequestModel
success:(void (^)(NSArray<ThingSmartMessageListModel *> *messageList))success
failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
listRequestModel | The request model for querying the message list. |
success | The success callback, which returns an array of messages. |
failure | The failure callback, which returns a failure reason. |
Data model of ThingSmartMessageListRequestModel
Field | Description |
---|---|
msgType | The message type. Valid values:
|
limit | The maximum number of messages that can be requested from the message list. |
offset | The total number of messages that have been requested from the message list. |
Sample code
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
}
API description
- (void)fetchEncryptMessageDetailListWithListRequestModel:(ThingSmartMessageDetailListRequestModel *)detailListRequestModel
success:(void (^)(NSArray<ThingSmartMessageListModel *> *messageList))success
failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
detailListRequestModel | The request model for querying message details. |
success | The success callback, which returns an array of message details. |
failure | The failure callback, which returns a failure reason. |
Data model of ThingSmartMessageDetailListRequestModel
Field | Description |
---|---|
msgType | The message type. Only alert (ThingMessageTypeAlarm ) is supported. |
limit | The maximum number of messages whose details can be requested from the details list. |
offset | The total number of messages whose details have been requested from the details list. |
msgSrcId | The ID of the device that sent the alert. |
Sample code
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
}
API description
- (void)fetchMessageDecryptKeyWithEncryptRequestModel:(NSArray<ThingSmartMessageEncryptRequestModel *> *)encryptRequestListModel
success:(void (^)(NSArray<ThingSmartMessageDecryptModel *> *messageList))success
failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
encryptRequestListModel | The request model for querying message keys. |
success | The success callback, which returns an array of message keys. |
failure | The failure callback, which returns a failure reason. |
Data model of ThingSmartMessageEncryptRequestModel
Field | Description |
---|---|
businessNo | The ID of the message. |
deviceId | The ID of the device that sent the alert. |
homeId | The ID of the home. |
time | The timestamp of the message. |
Data model of ThingSmartMessageDecryptModel
Field | Description |
---|---|
businessNo | The ID of the message. |
businessKey | The key of the message. |
Sample code
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
}
API description
- (void)deleteMessageWithDeleteRequestModel:(ThingSmartMessageListDeleteRequestModel *)deleteRequestModel
success:(ThingSuccessBOOL)success
failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
deleteRequestModel | The request model for deleting messages. |
success | The success callback. |
failure | The failure callback, which returns a failure reason. |
Data model of ThingSmartMessageListDeleteRequestModel
Field | Description |
---|---|
msgType | The message type. Valid values:
|
msgIds | The list of messages to delete. |
msgSrcId | The list of alerts to delete. |
:::Important
msgSrcIds
.ids
.msgIds
.Do not set the msgSrcIds
and ids
parameters at the same time. Otherwise, messages in the details list cannot be deleted.
:::
Sample code
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
}
API description
- (void)getLatestMessageWithSuccess:(ThingSuccessDict)success failure:(ThingFailureError)failure
Parameters
Parameter | Description |
---|---|
success | The success callback, which returns a dictionary that contains the following keys:
|
failure | The failure callback, which returns a failure reason. |
:::Important
The logic for determining whether a new message arises varies with the msgType
parameter that you specify in ThingSmartMessageListRequestModel
.
For home messages or notifications, if you call getLatestMessageWithSuccess:failure:
when a new message arises, true
is returned. If you call getLatestMessageWithSuccess:failure:
again after calling the API for querying the message list, the status result is set to false
.
For alerts, if you call the API for querying the message list after calling readMessageWithReadRequestModel:success:failure:
, the hasNotRead
field in ThingSmartMessageListModel
is set to false
.
:::
Sample code
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)")
}
})
API description
- (void)readMessageWithReadRequestModel:(ThingSmartMessageListReadRequestModel *)readRequestModel
success:(ThingSuccessBOOL)success
failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
readRequestModel | The request model for marking a message as read. |
success | The success callback. |
failure | The failure callback, which returns a failure reason. |
Data model of ThingSmartMessageListReadRequestModel
Field | Description |
---|---|
msgType | The message type. Only alert (ThingMessageTypeAlarm ) is supported. |
msgIds | The list of read messages. |
Sample code
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
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback