swiftsendbird

create 1 on 1 channel SendBird using swift


I am trying to create a one on one channel connection, however I am not able to figure out the format for creating an SDBUser. I am doing the following to try and create the channel.

SBDGroupChannel.createChannelWithUsers([("123456", "1234567"], isDistinct: true) { (channel, error) in
            if error != nil {
                NSLog("Error: %@", error!)
                return
            } else {
                //this means that the channel was successfully created
                print(channel)

                //segue to the open chat view
                //segue here DREW
            }
        }

Those Strings are the ID's as they appear in SendBird. There is an error that it expected type of SDBUser, and got String.

I have tried the following to get a SBDUser, but am getting the following value

let user1 = SBDUserListQuery.init(userIds: ["123456"])

but the user value is type SBDUserListQuery, so it still does not work.

I have not been able to find a solution in the SendBird docs


Solution

  • SendBird has various methods to create a group channel with user objects or user IDs. The method that you used is to create a channel with user objects. The following link is the another method with user IDs.

    https://docs.sendbird.com/ref/ios/Classes/SBDGroupChannel.html#//api/name/createChannelWithUserIds:isDistinct:completionHandler:

    The link is for Objective-C, but you could assume the same method in Swift like this:

    Swift 3:

    SBDGroupChannel.createChannel(withUserIds: ["123456", "1234567"], isDistinct: true) { (channel, error) in
        // Do something.            
            }
    

    And the SBDUserListQuery object is a query object to get a user list. If you want to get a user object from the query object, you have to call a load method.

    https://docs.sendbird.com/ref/ios/Classes/SBDUserListQuery.html#//api/name/loadNextPageWithCompletionHandler:

    The completionHandler block of the method returns the user list.

    Swift 3:

    let query = SBDUserListQuery(userIds: ["123456"]);
    query?.loadNextPage(completionHandler: { (users, error) in
    
            })