# Using SendBirdSDK and SendBirdUIKit together?

**URL:** <https://community.sendbird.com/t/using-sendbirdsdk-and-sendbirduikit-together/7107>\
**Category:** iOS\
**Created:** [April 21, 2023, 9:46pm UTC](https://community.sendbird.com/t/using-sendbirdsdk-and-sendbirduikit-together/7107 "2023-04-21T21:46:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tegan](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@tegan](https://community.sendbird.com/u/tegan)\
**Post date:** [April 21, 2023, 9:46pm UTC](https://community.sendbird.com/t/using-sendbirdsdk-and-sendbirduikit-together/7107/1 "2023-04-21T21:46:22Z")

</div>

**[Problem/Question]**  
I have an application in iOS that I would like to integrate chat into. I would like to leverage SendBirdUIKit for the UI.

I’ve asked ChatGTP how I can create a one to one chat experience. It tells me I need to use both SendBirdUIKit and the SendBirdSDK to achieve what I want to do. Here is what it is telling me:

**1. Install SendBirdUIKit and SendBirdSDK:**

You can install SendBirdUIKit and SendBirdSDK using CocoaPods or Swift Package Manager. Here, I will use CocoaPods:

Add the following to your `Podfile`:

```auto
platform :ios, '10.0'
use_frameworks!

target 'YourAppTarget' do
  pod 'SendBirdSDK'
  pod 'SendBirdUIKit'
end

```

Then, run `pod install` in your terminal to install the dependencies.

**2. Import SendBirdUIKit:**

In your ViewController or the file where you want to implement the chat functionality, import SendBirdUIKit:

```auto
import SendBirdUIKit

```

**3. Initialize SendBirdSDK:**

In your AppDelegate file, import SendBirdSDK and initialize it with your application ID within the `didFinishLaunchingWithOptions` method:

```auto
import SendBirdSDK

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    SBDMain.initWithApplicationId("YOUR_APP_ID")
    return true
}

```

Replace `"YOUR_APP_ID"` with your actual SendBird application ID.

**4. Connect to SendBird server:**

Before you can create a chat, you need to connect to the SendBird server with a user. Here’s an example of how to connect:

```auto
func connectToSendBird(userId: String, completionHandler: @escaping (Result<SBDUser, Error>) -> Void) {
    SBDMain.connect(withUserId: userId) { (user, error) in
        if let error = error {
            completionHandler(.failure(error))
        } else if let user = user {
            completionHandler(.success(user))
        }
    }
}

```

Call this function with a unique `userId` to connect to the SendBird server.

**5. Open one-on-one chat:**

After connecting to the server, use the following code to create a one-on-one chat:

```auto
func openOneToOneChat(targetUserId: String) {
    let channelListParams = SBDGroupChannelListQuery()
    channelListParams?.limit = 10
    channelListParams?.userIdsFilter = [targetUserId]
    channelListParams?.memberStateFilter = .joined

    channelListParams?.loadNextPage(completionHandler: { (channels, error) in
        if let error = error {
            print("Error loading channels: \(error)")
            return
        }
        
        if let channel = channels?.first {
            self.openChat(channel: channel)
        } else {
            self.createOneToOneChannel(targetUserId: targetUserId)
        }
    })
}

func createOneToOneChannel(targetUserId: String) {
    let params = SBDGroupChannelParams()
    params.isDistinct = true
    params.addUserIds([targetUserId])
    
    SBDGroupChannel.createChannel(with: params) { (channel, error) in
        if let error = error {
            print("Error creating channel: \(error)")
            return
        }
        
        if let channel = channel {
            self.openChat(channel: channel)
        }
    }
}

func openChat(channel: SBDGroupChannel) {
    let channelVC = SBUChannelViewController(channel: channel)
    let navigationController = UINavigationController(rootViewController: channelVC)
    self.present(navigationController, animated: true, completion: nil)
}

```

Call the `openOneToOneChat(targetUserId:)` function with the target user’s ID when you want to open a chat.

My question becomes… should I really be using both the UIKit and SDK to achieve this. My app has a little message user button next to each users profile. My goal is to make a function that passes the user information to sendbird and creates a one to one group channel then displays the chat box.

Important Note:  
The lastest knowledge ChatGTP 4 has on Sendbird UI is version version 2.1.2. So what it is suggest may be outdated. I am using the latest version.

* * *

// If problem, please fill out the below. If question, please delete.  
**[UIKit Version]**  
Latest

---

<div class="post-metadata">

**Author:** ![sardorbek.numonov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/sardorbek.numonov/32/697_2.png) [@sardorbek.numonov](https://community.sendbird.com/u/sardorbek.numonov)\
**Post date:** [April 24, 2023, 2:41am UTC](https://community.sendbird.com/t/using-sendbirdsdk-and-sendbirduikit-together/7107/2 "2023-04-24T02:41:24Z")

</div>

Hi @tegan.

[If you look at our documentation](https://docs.sendbird.com/docs/uikit/v3/ios/introduction/send-first-message#2-get-started), it is explained as follows.

- If you are using Swift Packages or CocoaPods, you don’t need to add `SendBirdChatSDK`.

- If you are using Carthage, then you need to add `SendBirdUIKit` and `SendBirdChatSDK` into your `Cartfile`.

Please follow our documentation. If you face a problem, please let us know.

Seems you are using Sendbird UIKit version 2. I recommend you use [Sendbird UIKit version 3](https://docs.sendbird.com/docs/uikit/v3/ios/overview)

---

<div class="post-metadata">

**Author:** ![tegan](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@tegan](https://community.sendbird.com/u/tegan)\
**Post date:** [April 27, 2023, 2:08am UTC](https://community.sendbird.com/t/using-sendbirdsdk-and-sendbirduikit-together/7107/3 "2023-04-27T02:08:50Z")

</div>

That did the trick! Thanks
