Messaging SDK migrate to 0.8.0 - Straas/Straas-iOS-sdk GitHub Wiki
This is a guiding page to show you how to migrate iOS messaging SDK to 0.8.0. If you never used iOS Messaging SDK under the version 0.8.0, you can skip this page.
##Interface change in STSChatEventDelegate
In order to unify the naming and make it consistent to other platforms, we change all of the naming chatRoom
in STSChatEventDelegate
to chatroom
.
For example:
//This is the STSChatEventDelegate under the version 0.8.0
- (void)chatRoomConnected:(NSString *)chatRoomName
- (void)chatRoomDisconnected:(NSString *)chatRoomName
- (void)chatRoom:(NSString *)chatRoomName failToConnect:(NSError *)error
...and so on...
//After 0.8.0 those STSChatEventDelegate change to
- (void)chatroomConnected:(STSChat *)chatroom
- (void)chatroomDisconnected:(STSChat *)chatroom
- (void)chatroom:(STSChat *)chatroom failToConnect:(NSError *)error
...and so on...
The first thing you may notice is that original naming chatRoom
is no longer used. We use chatroom
after version 0.8.0.
So, If you have used version 0.8.0 before, make sure you change all of the STSChatEventDelegate
method to fit our new version or the outdated delegate would not be called anymore!
The second thing is we are no longer using NSString chatRoomName
to notify which chatroom send the callback. We sent the STSChat object directly to let you know which chatroom send the STSChatEventDelegate
callback! The new design would make you easily to make your feature since you're no longer to use chatroomName to find the STSChat object. You can use the chat object directly.
For exmaple:
//This is the outdated way if you want to print out the userCount when `chatRoomUserCount:` event being called before 0.8.0.
- (void)chatRoomUserCount:(NSString *)chatRoomName {
__weak ChatViewController * weakSelf = self;
STSChat * chat = [weakSelf.manager chatForChatRoom:chatRoomName];
NSLog(@"%@ user count", chatRoomName);
}
//And this is the fashion way if you want to print out userCount when `chatroomUserCount:` event being called after 0.8.0
- (void)chatroomUserCount:(STSChat *)chatroom {
NSLog(@"%@ user count = %d", chatroom, (int)chatroom.userCount);
}
Looks better, right?
##Interface change in STSChatManager
The STSChatManager also change interface to make chatRoom
rename to chatroom
.
Here is the examples
//This is the STSChatManager method under the version 0.8.0
- (void)connectToChatRoom:(NSString *)chatRoomName JWT:(NSString *)JWT autoCreate:(BOOL)autoCreate
eventDelegate:(nullable id<STSChatEventDelegate>)eventDelegate;
- (void)disconnectFromChatRoom:(NSString *)chatRoomName;
- (void)getUsersForChatRoom:(NSString *)chatRoomName
success:(void(^)(NSArray<STSChatUser *> * users))success
failure:(void(^)(NSError * error))failure;
- (void)getMessagesForChatRoom:(NSString *)chatRoomName
success:(void(^)(NSArray<STSChatMessage *> * messages))success
failure:(void(^)(NSError * error))failure;
- (void)updateGuestNickname:(NSString *)nickname chatRoom:(NSString *)chatRoomName
success:(void(^)())success failure:(void(^)(NSError * error))failure;
... and so on ...
//After 0.8.0 those STSChatManager method change to
- (void)connectToChatroom:(NSString *)chatroomName JWT:(NSString *)JWT options:(STSChatroomConnectionOptions)options
eventDelegate:(nullable id<STSChatEventDelegate>)eventDelegate;
- (void)disconnectFromChatroom:(STSChat *)chatroom;
- (void)getUsersForChatroom:(STSChat *)chatroom
userType:(STSGetUsersType)userType
success:(void(^)(NSArray<STSChatUser *> * users))success
failure:(void(^)(NSError * error))failure;
- (void)getMessagesForChatroom:(STSChat *)chatroom
configuration:(STSGetMessagesConfiguration * _Nullable)configuration
success:(void(^)(NSArray<STSChatMessage *> * messages))success
failure:(void(^)(NSError * error))failure;
- (void)updateGuestNickname:(NSString *)nickname chatroom:(STSChat *)chatroom
success:(void(^)())success failure:(void(^)(NSError * error))failure;
... and so on ...
Also, we use STSChat object as input parameter instead of chatroomName to call the methods in STSChatManager.
You may use chatForChatroomName:isPersonalChat:
method to get the chat object.
For example:
// get chat object from STSChatManger
- (STSChat *)currentChat {
return [self.manager chatForChatroomName:self.chatroomName isPersonalChat:self.isPersonalChat];
}
// Send message
[self.manager sendMessage:@"message" chatroom:self.currentChat success:^{
} failure:(NSError * _Nonnull error) {
}];
For more details, you may reference our example migration in this commit and read our api docs.