> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started

> Getting Started — CometChat documentation.

## Start your first conversation

CometChat UI Kit for iOS is a package of pre-assembled UI elements crafted to streamline the creation of an in-app chat equipped with essential messaging functionalities. Our UI Kit presents options for light and dark themes, diverse fonts, colors, and extra customization capabilities.

CometChat UI Kit supports both one-to-one and group conversations. Follow the guide below to initiate conversations from scratch using CometChat iOS UI Kit.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/7emVxEQ5MCxvzC60/images/19d09825-getting_started_conversation_screens-95a0eb48e556b15224827c278ec89c05.png?fit=max&auto=format&n=7emVxEQ5MCxvzC60&q=85&s=2e0c4d6a2824b5222b22e7d4c7ffcded" width="4948" height="3120" data-path="images/19d09825-getting_started_conversation_screens-95a0eb48e556b15224827c278ec89c05.png" />
</Frame>

## Prerequisites

Before installing the **UI Kit**, you need to create a CometChat application on the CometChat Dashboard, which includes all the necessary data for a chat service, such as users, groups, calls, and messages. You will require the `App ID`, `AuthKey`, and `Region` of your CometChat application when initializing the SDK.

**i. Register on CometChat**

* You need to register on the **CometChat Dashboard** first. [Click here to sign up](https://app.cometchat.com/login).

**ii. Get Your Application Keys**

* Create a **new app**
* Head over to the **QuickStart** or **API & Auth Keys section** and note the **App ID**, **Auth Key**, and **Region**.

> Each CometChat application can be integrated with a single client app. Within the same application, users can communicate with each other across all platforms, whether they are on mobile devices or on the web.

**iii. IDE Setup**

* You have Xcode installed on your machine.
* You have an iOS device or simulator with iOS version 13.0 or above.
* Swift 5.0.
* macOS.

## Getting Started

Step 1

### Create a project

To get started, open Xcode and create a new project for UI Kit in the Project window as follows:

1. Select **iOS App** in the **Choose a template for your new project** window and click Next.
2. Enter your project name in the **Name** field in the **Choose options for your new project** window.
3. Enter your identifier in the **Bundle Identifier** field in the **Choose options for your new project** window.
4. Select **Storyboard** in the **Interface** field in the **Choose options for your new project** window.
5. Select **Swift** in the **Language** field in the **Choose options for your new project** window.

***

Step 2

### Add Dependency (Pods)

This developer kit is an add-on feature to CometChat iOS SDK so installing it will also install the core Chat SDK.

**1. CocoaPods**

We recommend using CocoaPods, as they are the most advanced way of managing iOS project dependencies. Open a terminal window, move to your project directory, and then create a Podfile by running the following command.

<Note>
  1. CometChatUIKitSwift supports installation through Cocoapods only. Currently, we are supporting Xcode 14 and higher.

  2. CometChatUIKitSwift supports iOS 13 and above
</Note>

```swift Swift theme={null}
$ pod init
```

Add the following lines to the Podfile.

```swift Swift theme={null}
platform :ios, '13.0'
use_frameworks!

target 'YourApp' do
  pod 'CometChatUIKitSwift', '5.1.7'
end
```

And then install the CometChatUIKitSwift framework through CocoaPods.

```swift Swift theme={null}
$ pod install
```

If you're facing any issues while installing pods then use the below command.

```swift Swift theme={null}
$ pod install --repo-update
```

Always get the latest version of CometChatUIKitSwift by command.

```swift Swift theme={null}
$ pod update CometChatUIKitSwift
```

<Tip>
  Always ensure to open the XCFramework file after adding the dependencies.
</Tip>

**2. Swift Package Manager.**

1. Go to your Swift Package Manager's **File** tab and select **Add Package Dependencies.**

2) Add `CometChatUIKitSwift` into your `Package Repository` as below:

```sh Bash theme={null}
https://github.com/cometchat/cometchat-uikit-ios.git
```

3. To add the package, select Version Rules, enter Up to Exact Version, **4.3.20,** and click Next.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/FGBCGWXGo5d9bVxR/images/c1ef0125-nogixsjkzujng1zm7320ka4091pnidywenq49indeiy0x4a71u8at7frr28otqs4-8056caf63c9274d5d8f4bf32a786c383.png?fit=max&auto=format&n=FGBCGWXGo5d9bVxR&q=85&s=fe1f1039c1d842c2a1607933e9269462" width="1566" height="609" data-path="images/c1ef0125-nogixsjkzujng1zm7320ka4091pnidywenq49indeiy0x4a71u8at7frr28otqs4-8056caf63c9274d5d8f4bf32a786c383.png" />
</Frame>

4. Once, the package is added it will look like this.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/xIG5VBdyNJ5cYSqE/images/cfcc90a0-rwo9l9eze7srvnfxcfewvsnsdpsspl7v8bsdspotpdfsn3l1xnhf8v4x3x46v6oz-1a191dd110d481895eff3728b54c35fd.png?fit=max&auto=format&n=xIG5VBdyNJ5cYSqE&q=85&s=9abdde020878fbe87974247a1b2f338a" width="520" height="548" data-path="images/cfcc90a0-rwo9l9eze7srvnfxcfewvsnsdpsspl7v8bsdspotpdfsn3l1xnhf8v4x3x46v6oz-1a191dd110d481895eff3728b54c35fd.png" />
</Frame>

***

Step 3

### Permissions

* Allow Camera, Microphone and photo Library access in Info.plist

* UI Kit provides the feature of media messages, so these settings are required.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/FGBCGWXGo5d9bVxR/images/c47314fe-qlfi45slhwc6t1ywabqv6u6mqzya3yha4ohca2tm1pdafarz4zesoqeq6ca8jd93-08eb1fad754cb08c582113850d5eb19d.png?fit=max&auto=format&n=FGBCGWXGo5d9bVxR&q=85&s=945a6aea71cd51257349efd6dbadab2d" width="1248" height="148" data-path="images/c47314fe-qlfi45slhwc6t1ywabqv6u6mqzya3yha4ohca2tm1pdafarz4zesoqeq6ca8jd93-08eb1fad754cb08c582113850d5eb19d.png" />
</Frame>

* Navigate to your build settings.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/PaxBG9I1yMoeQmt2/images/35597350-screenshot_2024-03-20_at_6.40.02_PM-32ff7accc7671b14393caf0b0694f2c6.png?fit=max&auto=format&n=PaxBG9I1yMoeQmt2&q=85&s=95606b56489350bd316661098b23ccb7" width="1396" height="1154" data-path="images/35597350-screenshot_2024-03-20_at_6.40.02_PM-32ff7accc7671b14393caf0b0694f2c6.png" />
</Frame>

* Disable the User Script Sandboxing option.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/Gp90C5sdVtuRR4t7/images/8086b38b-screenshot_2024-03-20_at_6.40.31_PM-9b0abfea8326a2edbbc45be0db6094d3.png?fit=max&auto=format&n=Gp90C5sdVtuRR4t7&q=85&s=af233d269ca737f8777b1ba051da889c" width="1522" height="52" data-path="images/8086b38b-screenshot_2024-03-20_at_6.40.31_PM-9b0abfea8326a2edbbc45be0db6094d3.png" />
</Frame>

***

Step 4

### Initialize CometChatUIkit

To seamlessly integrate CometChat UI Kit into your app, initialize it using the `init( )` method. This ensures all necessary settings are configured for CometChatUIKit.

It's crucial to call this method on app startup before using any other functions from CometChat UI Kit or CometChat SDK.

Initialize CometChatUIkit within your **app delegate's** `didFinishLaunchingWithOptions method`.

<Note>
  The Auth Key is an optional property of the `UIKitSettings` Class. It is intended for use primarily during proof-of-concept (POC) development or in the early stages of application development. You can use the [Auth Token](/ui-kit/ios/v4/methods#how-to-login-a-user-with-auth-token) method to log in securely.
</Note>

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    import CometChatUIKitSwift
     let uikitSettings = UIKitSettings()
          uikitSettings.set(appID: <# Enter Your App ID Here #>)
                       .set(authKey: <# Enter Your AuthKey Here #>)
                       .set(region: <# Enter Your Region Code Here #> )
                       .subscribePresenceForAllUsers()
                       .build()
           CometChatUIKit.init(uiKitSettings: uikitSettings, result: {
                      result in
                      switch result {
                    case.success(let success):
                        debugPrint("Initialization completed successfully \(success)")
                        break
                        case.failure(let error):
                        debugPrint( "Initialization failed with exception: \(error.localizedDescription)")
                        break
                      }
                    })
    ```
  </Tab>
</Tabs>

> Make sure to replace the **appId** with your CometChat appId and **region** with your app region in the above code.

***

Step 5

### Login User

For login, you require a `UID`. You can create your own users on the CometChat Dashboard or via API. We have pre-generated test users: `cometchat-uid-1`, `cometchat-uid-2`, `cometchat-uid-3`, `cometchat-uid-4`, `cometchat-uid-5`.

The [Login](/ui-kit/ios/v4/getting-started#login-user) method returns the User object containing all the information of the logged-in user.

<Note>
  This straightforward authentication method is ideal for proof-of-concept (POC) development or during the early stages of application development. For production environments, however, we strongly recommend using an [Auth Token](/ui-kit/ios/v4/methods#how-to-login-a-user-with-auth-token) instead of an Auth Key to ensure enhanced security.
</Note>

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let uid = <# Enter User's UID Here #>

        CometChatUIKit.login(uid: uid) { result in
                switch result {
                case .success(let user):
                    debugPrint("User logged in successfully  \(user.name)")
                  break
                case .onError(let error):
                    debugPrint("Login failed with exception: \(error.errorDescription)")
                  break
                }
         }
    ```
  </Tab>
</Tabs>

> Make sure you replace the authKey with your CometChat Auth Key in the above code.

***

Step 6

### Render Conversation With Message

[CometChatConversationsWithMessages](/ui-kit/ios/v4/conversations-with-messages) is a wrapper component that offers functionality to render both the [Conversations](/ui-kit/ios/v4/conversations) and [Messages](/ui-kit/ios/v4/messages) components. It also enables opening the [Messages](/ui-kit/ios/v4/messages) by tapping on any conversation rendered in the list of conversations.

Since **CometChatConversationsWithMessages** is a view controller, it can be launched either by a button click or through any event's trigger. It inherits all the customizable properties and methods of `CometChatConversations.`

**View Controller**: To use ConversationsWithMessages in your `view controller`, use the following code snippet.

```swift view controller theme={null}
let cometChatConversationsWithMessages = CometChatConversationsWithMessages()
self.navigationController?.pushViewController(cometChatConversationsWithMessages, animated: true)
```

<Info>
  It will automatically fetch the conversation data upon loading the list. If the conversation list is empty, you can start a new conversation.
</Info>

***

**Scene Delegate**: To use ConversationsWithMessages in your `Navigation controller,` use the following code snippet in your `willConnectTo` method in SceneDelegate.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
     let cometChatConversationsWithMessages = CometChatConversationsWithMessages()
            let naviVC = UINavigationController(rootViewController: cometChatConversationsWithMessages)

            window?.rootViewController = naviVC
    ```

    <Note>
      make sure to \`import CometChatUIKitSwift\`
    </Note>
  </Tab>
</Tabs>

***
