English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Message Capabilities

Last Updated on : 2022-01-04 07:29:32download

Query a list of messages

API description

- (void)getMessageList:(void (^)(NSArray<TuyaSmartMessageListModel *> *list))success
               failure:(TYFailureError)failure

Parameters

Parameter Description
success The success callback. An array of messages is returned.
failure The failure callback. An error message is returned.

Example

ObjC:

//    self.smartMessage = [[TuyaSmartMessage alloc] init];
	[self.smartMessage getMessageList:^(NSArray<TuyaSmartMessageListModel *> *list) {
		NSLog(@"get message list success:%@", list);
	} failure:^(NSError *error) {
		NSLog(@"get message list failure:%@", error);
	}];

Swift:

    smartMessage?.getList({ (list) in
        print("get message list success: \(list)")
    }, failure: { (error) in
        if let e = error {
            print("get message list failure: \(e)")
        }
    })

Query a list of messages on pages

API description

- (void)getMessageList:(NSInteger)limit
                offset:(NSInteger)offset
               success:(void (^)(NSArray<TuyaSmartMessageListModel *> *list))success
               failure:(TYFailureError)failure

Parameters

Parameter Description
limit The maximum number of entries to be returned per page.
offset The total number of messages already returned.
success The success callback. An array of messages is returned.
failure The failure callback. An error message is returned.

Example

//  self.smartMessage = [[TuyaSmartMessage alloc] init];
    NSNumber *limit = @15;
    NSNumber *offset = @0;
    [self.smartMessage getMessageList:limit offset:offset success:^(NSArray<TuyaSmartMessageListModel *> *list) {
        NSLog(@"get message list success:%@", list);
    } failure:^(NSError *error) {
        NSLog(@"get message list failure:%@", error);
    }];

Query messages on pages by message type

API description

- (void)getMessageListWithType:(NSInteger)msgType limit:(NSInteger)limit offset:(NSInteger)offset success:(void (^)(NSArray<TuyaSmartMessageListModel *> *list))success failure:(TYFailureError)failure

Parameters

Parameter Description
msgType The type of message. Valid values:
  • 1: alert
  • 2: home message
  • 3: notification
limit The maximum number of entries to be returned per page.
offset The total number of messages already returned.
success The success callback. An array of messages is returned.
failure The failure callback. An error message is returned.

Example

//   self.smartMessage = [[TuyaSmartMessage alloc] init];
    NSNumber *limit = @15;
    NSNumber *offset = @0;
    [self.smartMessage getMessageList:limit offset:offset success:^(NSArray<TuyaSmartMessageListModel *> *list) {
        NSLog(@"get message list success:%@", list);
    } failure:^(NSError *error) {
        NSLog(@"get message list failure:%@", error);
    }];

Query message details by message group ID

API description

- (void)getMessageDetailListWithType:(NSInteger)msgType msgSrcId:(NSString *)msgSrcId limit:(NSInteger)limit offset:(NSInteger)offset success:(void (^)(NSArray<TuyaSmartMessageListModel *> *list))success failure:(TYFailureError)failure

Parameters

Parameter Description
msgType The type of message. Valid values:
  • 1: alert
  • 2: home message
  • 3: notification
msgSrcId The message group ID.
limit The maximum number of entries to be returned per page.
offset The total number of messages already returned.
success The success callback with an array of DND periods returned.
failure The failure callback. An error message is returned.

Example

		//   self.smartMessage = [[TuyaSmartMessage alloc] init];
    NSNumber *limit = @15;
    NSNumber *offset = @0;
    [self.smartMessage getMessageDetailListWithType:1 msgSrcId:@"xxx" limit offset:offset success:^(NSArray<TuyaSmartMessageListModel *> *list) {
        NSLog(@"get message list success:%@", list);
    } failure:^(NSError *error) {
        NSLog(@"get message list failure:%@", error);
    }];

Delete messages

Delete messages in bulk

API description

- (void)deleteMessage:(NSArray <NSString *> *)messgeIdList
              success:(TYSuccessHandler)success
              failure:(TYFailureError)failure

Parameters

Parameter Description
messgeIdList The list of IDs for the messages to be deleted.
success The success callback.
failure The failure callback. An error message is returned.

Example

ObjC:

//  self.smartMessage = [[TuyaSmartMessage alloc] init];
    [self.smartMessage deleteMessage:(NSArray <NSString *> *)messgeIdList success:^{
        NSLog(@"delete message success");
    } failure:^(NSError *error) {
        NSLog(@"delete message failure:%@", error);
    }];

Swift:

    smartMessage?.delete(["messgeIdList"], success: {
        print("delete message success")
    }, failure: { (error) in
        if let e = error {
            print("delete message failure: \(e)")
        }
    })

Delete messages of specific type

API description

- (void)deleteMessageWithType:(NSInteger)msgType ids:(NSArray *)ids msgSrcIds:(NSArray *)msgSrcIds success:(TYSuccessHandler)success failure:(TYFailureError)failure

Parameters

Parameter Description
msgType The type of message. Valid values:
  • 1: alert
  • 2: home message
  • 3: notification
ids The list of IDs for the messages to be deleted.
msgSrcIds The list of alert IDs. A value of nil or @[] represents that alerts are not deleted.
success The success callback.
failure The failure callback. An error message is returned.
  • To delete items from the alert list, you must set the parameter msgSrcIds.
  • To delete items from the list of alert details, you must set the parameter ids.

The parameters msgSrcIds and ids cannot be set in the same request. Otherwise, the specified items in the list of alert details cannot be deleted.

Example

ObjC:

//    self.smartMessage = [[TuyaSmartMessage alloc] init];
    [self.smartMessage deleteMessageWithType:msgType ids:ids msgSrcIds:nil success:^{
        NSLog(@"delete message success");
    } failure:^(NSError *error) {
        NSLog(@"delete message failure:%@", error);
    }];

Check for new messages

API description

- (void)getLatestMessageWithSuccess:(TYSuccessDict)success failure:(TYFailureError)failure

Parameters

Parameter Description
success The success callback. Data in the dictionary format is returned. The following keys are supported:
  • alarm: alert
  • family: home message
  • notification: notification
failure The failure callback. An error message is returned.

Example

ObjC:

//      self.smartMessage = [[TuyaSmartMessage 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)")
        }
    })