Messages and the iOS SDK
Sending a Message
Step 1: Create TTMessageRequest Object
Objective-C
TTMessageRequest *messageRequest = [[TTMessageRequest alloc] initWithRecipientToken:user.token];messageRequest.messageText = text;messageRequest.timeToLive = kMessageTimeToLive;messageRequest.deleteOnRead = kDeleteOnRead;
Swift
let messageRequest = TTMessageRequest.init(recipientToken: user.token)messageRequest.timeToLive = kMessageTimeToLive // MinutesmessageRequest.messageText = textmessageRequest.organizationToken = organizationTokenmessageRequest.messagePriority = sendPriorityMessage ? .high : .normal
Step 2: Process the Request with TTKit
Objective-C
[[TTKit sharedInstance] sendMessageWithRequest:messageRequestcompletion:^(TTMessage *message, NSError *error) {}];
Swift
TTKit.sharedInstance().sendMessage(with: messageRequest) { (message: TTMessage?, _: Error?) in}
Send Attachments
To send a message with attachments, please specify the MIME type. You can pass an NSData object or a file path to the data you wish to upload as the attachment (using the file path for larger files). The max attachment size is currently 100MB.
messageRequest.attachmentData = data;messageRequest.attachmentMimeType = @"image/jpeg";messageRequest.attachmentFilePath = @"attachment_local_file_path";messageRequest.attachmentMimeType = @"image/jpeg";
Marking a Message as Read
Marking a specific message as Read
[[TTKit sharedInstance] markMessageAsRead:message];
Mark all unread messages in a roster entry (conversation) as Read
[[TTKit sharedInstance] markAllUnreadMessagesAsRead:self.rosterEntry success:^{} failure:^(NSError * _Nullable error) {}];
Recall/Delete Message
If you delete your own message that message will be removed for other recipients as well, if you delete a message you didn't send it will only be deleted for you.
[[TTKit sharedInstance] deleteMessage:message];
Forward a Message
Use the forwardMessage
method to forward a message to a user or group, if you wish to forward the message as a role (you currently own and opted into) pass the TTRole
object in asRole
:
[[TTKit sharedInstance] forwardMessage:messageTokenasRole:roleYouOwnrecipient:user.tokenpriorityMessage:TTMessagePriorityNormal success:^{ } failure:^(NSError * _Nullable error) { }];
Next Steps
If you need more information about our SDK you can check out the SDK Reference.