Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Migration guide

Sendbird Chat SDK v4 for iOS has introduced major breaking changes to streamline the code structure and enhance its scalability.

This page explains the breaking changes and provides a step-by-step guide for migrating to v4.


Requirements

The minimum requirements for v4 are the following.

  • macOS
  • Xcode
  • At least one device running iOS 9.0 and later
  • Swift 5.0 and later or Objective-C

Breaking changes

The following breaking changes have been made to the Chat SDK v4 for iOS.

Structural changes

  • Remove the SBD prefix across names for all constants, protocols, classes, enums, and type definitions.

  • Rename the main class from SBDMain to SendbirdChat.

  • Creation of Sendbird instances is no longer available in v4.

  • Rename SBDError to SBError.

  • Add didConnect(userId:) and didDisconnect(userId:) to ConnectionDelegate.

  • Split SBDChannelDelegate into BaseChannelDelegate, GroupChannelDelegate, and OpenChannelDelegate.

  • Remove SBDUserListQuery. Use specific queries such as ApplicationUserListQuery and BlockedUserListQuery to query users instead.

  • Add the requestId to the file onProgress interface. Change interface FileMessagesWithProgressHandler, fun onProgress(bytesSent: Int, totalBytesSent: Int, totalBytesToSend: Int) to fun onProgress(requestId: String, bytesSent: Int, totalBytesSent: Int, totalBytesToSend: Int)

  • Separate existing params such as SBDUserMessageParams into UserMessageCreateParams and UserMessageUpdateParams.

  • Channel’s member default value has been changed from nil to [].

  • User’s nickname default value has been changed from nil to "".

From v3To v4

SBDGroupChannelParams

GroupChannelCreateParams
GroupChannelUpdateParams

SBDOpenChannelParams

OpenChannelCreateParams
OpenChannelUpdateParams

SBDUserMessageParams

UserMessageCreateParams
UserMessageUpdateParams

SBDFileMessageParams

FileMessageCreateParams
FileMessageUpdateParams

Name changes

From v3To v4

SBDMain

SendbirdChat

The SBD prefix for constants, protocols, classes, enums, and type definitions

All SBD prefix removed

SBDError

SBError

SendBirdError

SendbirdError

SBDOptions

SendbirdChatOptions

SendbirdChat.Options.useMemberAsMessageSender

SendbirdChat.Options.useMemberInfoInMessage

getChannelCount

getGroupChannelCount

getChannelCountWithMemberStateFilter:...

getGroupChannelCountWithMemberStateFilter:...

getMyGroupChannelChangeLogs(ByTimestamp ...)

getMyGroupChannelChangeLogs(timestamp)

getMyGroupChannelChangeLogs(ByToken ...)

getMyGroupChannelChangeLogs(token)

isUsingLocalCaching

isLocalCachingEnabled

memberStateFilter: MemberStateFilter

myMemberStateFilter: MyMemberStateFilter

Note: A full list of name changes will be available soon.

Other changes

  • Remove SBDConnectionManager, which was deprecated in v3.

  • Local caching in the SDK v4 can facilitate caching-related functionalities and more. SyncManager will soon be deprecated, therefore we highly recommend to use local caching instead.

  • Remove setters for Query classes and add corresponding Params classes.

  • Mappable protocol is no longer supported. Instead, use Swift's Codable to serialize and deserialize objects. It stays the same for Objective-C.


Migrating to v4

The following is a step-by-step guide which covers the changes and key steps required when migrating from the Chat SDK v3 to v4.

Sendbird Chat SDK v4 will likely prevent your app from compiling until all migration tasks are complete and all errors are fixed. After fixing all the blocking errors, further work may be needed to remove warnings and align the SDK with your app again. We recommend you allow a generous timeline for the task. Depending on the level of dependency, it may take a few hours to a week.

Step 1 Replace SDK import names

It's recommended to remove any deprecated methods from the Chat SDK v3 since v4 will likely have a long list of errors. Find and replace all instances of import SendBirdSDK with import SendbirdChatSDK. Notice that the "b" in Sendbird is now lowercase.

Step 2 Replace SBDError

Find and replace all instances of SBDError with SBError.

Step 3 Replace SBDMain

Find and replace all instances of SBDMain with SendbirdChat.

Step 4 Remove the prefix SBD

Find and remove all the SBD prefix from all names for constants, protocols, classes, enums, and other type declarations.

Step 5 Handle common errors

The following are manual fixes to errors that may arise when migrating to v4.

The following are possible method-related errors you may see in Xcode.

  • Missing arguments for parameters params, completionHandler in call.
  • Extra arguments at positions #1, #2, #3, #4, #5, #6, #8 in call.
  • Extra argument in call.

For example, updating channel information with individual parameters as in v3 may cause one or more of the errors listed above.

In v4, you can fix the error by externally declaring method params by following the code below.

func updateChannelInfo() {
   channel.update(withName:"Some new name", coverImage: imageData, coverImageName: "image.jpg", data: nil, operatorUserIds: nil, customType: nil, progressHandler: nil) { (channel, error) in
      ...
   }
}
let openChannelUpdateParams = OpenChannelUpdateParams()
openChannelUpdateParams.name = "Some new name"
openChannelUpdateParams.coverImage = imageData
openChannelUpdateParams.coverImageName = "image.jpg"
    
channel.update(params: openChannelUpdateParams) { channel, error in
   ...
}

Errors with assigning nil in parameter

In v4, some parameter fields do not need to be explicitly assigned as nil. The following errors may be seen in Xcode.

  • Type of expression is ambiguous without more context.
  • nil requires a contextual type.

The nil assigned fields, data and customType can be deleted because the SDK will automatically assign the values as nil.

let fileMessageParams = FileMessageCreateParams(file: imageData)
fileMessageParams.fileName = imageName
fileMessageParams.mimeType = mimeType
fileMessageParams.fileSize = UInt(imageData.count)
fileMessageParams.thumbnailSizes = [thumbnailSize] as [ThumbnailSize]
fileMessageParams.data = nil
fileMessageParams.customType = nil
let fileMessageParams = FileMessageCreateParams(file: imageData)
fileMessageParams.fileName = imageName
fileMessageParams.mimeType = mimeType
fileMessageParams.fileSize = UInt(imageData.count)
fileMessageParams.thumbnailSizes = [thumbnailSize] as [ThumbnailSize]

Channel delegate errors

The SBDChannelDelegate is split into BaseChannelDelegate, GroupChannelDelegate, and OpenChannelDelegate. Therefore, the previous channel delegate needs to be changed and may come across the error below in Xcode.

  • Cannot find type ChannelDelegate in scope.

In this case, the suggested fix is to consider the context of the class to determine which delegate is required. For example, AppDelegate likely requires BaseChannelDelegate instead of the original SBDChannelDelegate.

Name change errors

In v4, some of the param classes have been separated and renamed. For example, GroupChannelParams was split to GroupChannelCreateParams or GroupChannelUpdateParams. Thus, the following error may be seen in Xcode.

  • Cannot find type XXXParams in scope.

In this case, the suggested fix is to use Xcode's autocomplete, or Sendbird docs to find relevant name changes.

In v3, casting MutedUserListQuery, BannedUserListQuery, and ParticipantListQuery to UserListQuery was possible.

In v4, the changes made to the query model no longer works in the same pattern as in v3. UserListQuery has changed to ApplicationUserListQuery and each query type must be declared individually.

private var userListQuery: UserListQuery?       
if self.userListQuery == nil {
   switch userListType {
   case .banned:
      self.userListQuery = channel.createBannedUserListQuery { $0.limit = 20 }
   case .muted:
     self.userListQuery = channel.createMutedUserListQuery { $0.limit = 20 }
   case .participant:
     self.userListQuery = channel.createParticipantUserListQuery { $0.limit = 20 }
   }
}
private var bannedUserListQuery: BannedUserListQuery?
private var mutedUserListQuery: MutedUserListQuery?
private var participantListQuery: ParticipantUserListQuery?
       
switch userListType {
   case .banned:
      self.bannedUserListQuery = channel.createBannedUserListQuery()
   case .muted:
      self.mutedUserListQuery = channel.createMutedUserListQuery()
   case .participant:
      self.participantUserListQuery = channel.createParticipantUserListQuery()
}