> ## 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.

# Setup

> Setup — CometChat documentation.

<Note>
  Migrating app version from v2 to v3 ?

  Skip the create new app step. Your existing v2 app can be migrated to v3.\
  \
  Follow steps mentioned in **Add the CometChat dependency** section below to upgrade to latest version of v3
</Note>

## Get your Application Keys

[Signup for CometChat](https://app.cometchat.com) and then:

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

<Tip>
  Minimum Requirement

  1. Xcode 12 (or Higher)
  2. iOS 11 or higher
</Tip>

***

## Add the CometChat Dependency

### CocoaPods

We recommend using [CocoaPods](https://cocoapods.org/), 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.

<Warning>
  1. CometChatPro SDK supports installation through Cocoapods and SPM both. Currently, we are supporting Xcode 11.4 and higher.
  2. CometChatPro SDK includes video calling components. We suggest you run on physical devices to avoid errors.
</Warning>

<Tabs>
  <Tab title="Swift">
    ```bash theme={null}
    $ pod init
    ```
  </Tab>
</Tabs>

Add the following lines to the Podfile.

<Tabs>
  <Tab title="Swift">
    ```ruby theme={null}
    platform :ios, '11.0'
    use_frameworks!

    target 'MyApp' do
      pod 'CometChatPro', '3.0.919'
    end
    ```
  </Tab>
</Tabs>

<Tip>
  Minimum Requirement

  v3.0.2+ onwards, Voice & Video Calling functionality has been moved to a separate framework. In case you do not plan to use the calling feature, please add the Calling framework `pod 'CometChatCalls', '3.0.0'` in your app Podfile.
</Tip>

And then install the `CometChatSDK` framework through CocoaPods.

<Tabs>
  <Tab title="Swift">
    ```bash theme={null}
    $ pod install
    ```
  </Tab>
</Tabs>

Always get the latest version of `CometChatSDK` by command

<Tabs>
  <Tab title="Swift">
    ```bash theme={null}
    $ pod update CometChatPro
    ```
  </Tab>
</Tabs>

### Swift Packages

To install **Swift Packages** you can use Xcode package manager\*\*.\*\*

1. Open **Xcode**, go to the project's **General** settings tab and select the project under **Project** in the left column.
2. Go to the **Swift packages** tab and click on the **+** button.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/mNTojjz_O28of40c/images/fa786752-1634032671-f0fc1c00c9f33cca47875131228648cb.png?fit=max&auto=format&n=mNTojjz_O28of40c&q=85&s=b81e662aa4ecdd865b256b2b46dcede9" width="1919" height="1055" data-path="images/fa786752-1634032671-f0fc1c00c9f33cca47875131228648cb.png" />
</Frame>

3. Once the pop-up appears, enter the github repository address in the search bar [`https://github.com/cometchat/chat-sdk-ios.git`](https://github.com/cometchat/chat-sdk-ios.git) and set dependency rule to `Up to Next Major Version` and set version as `3.0.919` . Then click on the **Add Package** button.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/7emVxEQ5MCxvzC60/images/1a15e3d6-lpicmoo6ec63qc5tzshr3flcis5wyab1nf1fpeumo5b1ltq4lpj8w9cofpwuwvq1-88cf2d220c36043db932c1d01c1daa4d.png?fit=max&auto=format&n=7emVxEQ5MCxvzC60&q=85&s=13b6c46ee6caf89a5c21cc601b73e35a" width="1038" height="605" data-path="images/1a15e3d6-lpicmoo6ec63qc5tzshr3flcis5wyab1nf1fpeumo5b1ltq4lpj8w9cofpwuwvq1-88cf2d220c36043db932c1d01c1daa4d.png" />
</Frame>

4. `CometChatPro` must be checked in the **Package Product** column and click on the Add Package button. This will add **Package Dependencies** menu in Xcode.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/ugckbRl5Q-H7t8X2/images/e672b0a6-1634032799-4c72389bafd2a791b02af2db085bc577.png?fit=max&auto=format&n=ugckbRl5Q-H7t8X2&q=85&s=399e8206ed55592c411d4bed86dfcdd0" width="659" height="299" data-path="images/e672b0a6-1634032799-4c72389bafd2a791b02af2db085bc577.png" />
</Frame>

### Request Authorization

Prepare your app for this requirement by providing justification strings. The justification string is a localizable message that you add to your app's `Info.plist` file to tell the user why your app needs access to the user's photo library, Camera, Microphone. Then, App prompts the user to grant permission for access, the alert displays the justification string you provided, in the language of the locale selected on the user's device. You can do this as follows:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/7a4hqm7gLVRmX34O/images/0119d1bb-1623200477-7bdad6acb11779de4a98a154e785d56a.png?fit=max&auto=format&n=7a4hqm7gLVRmX34O&q=85&s=accd167974c82e10f9281e54c694f0b6" width="1020" height="362" data-path="images/0119d1bb-1623200477-7bdad6acb11779de4a98a154e785d56a.png" />
</Frame>

<Tabs>
  <Tab title="Info.plist">
    ```xml theme={null}
    <key>NSAppTransportSecurity</key>
      <dict>
    	  <key>NSAllowsArbitraryLoads</key>
    	  <true />
      </dict>
    <key>NSCameraUsageDescription</key>
    	<string>$(PRODUCT_NAME) need access to the camera in order to update your avatar</string>
    <key>NSPhotoLibraryUsageDescription</key>
    	<string>$(PRODUCT_NAME) need access to the Photo Library in order to send Media Messages</string>
    <key>NSMicrophoneUsageDescription</key>
    	<string>$(PRODUCT_NAME) need access to the Microphone in order to connect Audio/Video call </string>
    ```
  </Tab>
</Tabs>

### Setup Bitcode

You can set the Enable Bitcode setting to YES present in build settings in your XCode project.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/_MYSdWhXnUkTkjEH/images/477193c3-1631809611-db96539a98643ad55b7950d86d4b6557.png?fit=max&auto=format&n=_MYSdWhXnUkTkjEH&q=85&s=cdb80371bbba202c0083b53a88e791ed" width="1238" height="123" data-path="images/477193c3-1631809611-db96539a98643ad55b7950d86d4b6557.png" />
</Frame>

<Warning>
  If you are using CometChat Pro SDK having the version less than 2.0.8, then you need to set **Enable Bitcode** to **NO**
</Warning>

### Swift Standard Libraries

`CometChatPro`framework build on Swift, you have to ensure the required libraries are embedded. This can be done by setting the `“Always Embed Swift Standard Libraries”` checkbox in your target’s build settings to “Yes”:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/mq8rEbFfi0JjKmkM/images/6ae89ab8-1623200430-15b0442a710f78a45dd01090dc6a32f1.png?fit=max&auto=format&n=mq8rEbFfi0JjKmkM&q=85&s=7bed5786919b0d5d17dbd473c61cd1d4" width="861" height="191" data-path="images/6ae89ab8-1623200430-15b0442a710f78a45dd01090dc6a32f1.png" />
</Frame>

### Set Header Search Path

Set the `Header Search Paths` to `$SDKROOT/usr/include/libxml2`.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/le8ibYc8lBJsShSE/images/57d60afc-1631809733-acc69d5f571a8aac9ac8683e9f1ed0eb.png?fit=max&auto=format&n=le8ibYc8lBJsShSE&q=85&s=3bf45d8961977ed3d93554b3f572a034" width="861" height="389" data-path="images/57d60afc-1631809733-acc69d5f571a8aac9ac8683e9f1ed0eb.png" />
</Frame>

Excluded Architecture

<Warning>
  For Xcode 12 and above, we need to add arm64 in the excluded architecture of build settings as Apple supports only arm architecture for simulators and actual devices. No support provided for X86\_64 and i386 architectures.
</Warning>

### Setting for build for active architecture

<Tip>
  In Build Settings, enable active architecture to Yes
</Tip>

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/7a4hqm7gLVRmX34O/images/03d9b800-1631809819-9693b622c55029f8fe4480d4f7481b65.png?fit=max&auto=format&n=7a4hqm7gLVRmX34O&q=85&s=142fad995e440989e9d1c27d5c16c7ae" width="1646" height="624" data-path="images/03d9b800-1631809819-9693b622c55029f8fe4480d4f7481b65.png" />
</Frame>

***

## Initialize CometChat

The `init()` method initializes the settings required for CometChat.

The `init()` method takes the below parameters:

1. appID - You CometChat App ID
2. appSettings - An object of the AppSettings class can be created using the AppSettingsBuilder class. The region field is mandatory and can be set using the `setRegion()` method.

The `AppSettings` class allows you to configure three settings:

* **Region**: The region where you app was created.
* **[Presence Subscription](/sdk/ios/3.0/user-presence) :** Represents the subscription type for user presence (real-time online/offline status)
* **autoEstablishSocketConnection(boolean value)**: This property takes a boolean value which when set to true informs the SDK to manage the web-socket connection internally. If set to false, it informs the SDK that the web-socket connection will be managed manually. The default value for this parameter is true. For more information on this, please check the [Managing Web-Socket connections manually](/sdk/ios/3.0/managing-web-socket-connections-manually) section. The default value for this property is **true.**
* **overrideAdminHost(adminHost: string)**: This method takes the admin URL as input and uses this admin URL instead of the default admin URL. This can be used in case of dedicated deployment of CometChat.
* **overrideClientHost(clientHost: string)**: This method takes the client URL as input and uses this client URL instead of the default client URL. This can be used in case of dedicated deployment of CometChat.

We suggest you call the method on app startup preferably in the `didFinishLaunchingWithOptions:` method of the `AppDelegate` class.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    import CometChatPro

    class AppDelegate: UIResponder, UIApplicationDelegate{
    {
       var window: UIWindow?
       let appId: String = "ENTER APP ID"
       let region: String = "ENTER REGION CODE"
        
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    let mySettings = AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region: region).build()
            
      CometChat.init(appId: appId ,appSettings: mySettings,onSuccess: { (isSuccess) in
                if (isSuccess) {
                    print("CometChat Pro SDK intialise successfully.")
                }
            }) { (error) in
                    print("CometChat Pro SDK failed intialise with error: \(error.errorDescription)")
            }
            return true
        }
    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    #import <CometChatPro/CometChatPro-Swift.h>

    @interface AppDelegate ()

    @end

    @implementation AppDelegate


    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      
      NSString *region = @"REGION";
      NSString *appID = @"YOUR_APP_ID";
        
        AppSettingsBuilder *appSettingBuilder = [[AppSettingsBuilder alloc]init];
        AppSettings *appSettings = [[[appSettingBuilder subscribePresenceForAllUsers]setRegionWithRegion:region]build];
        
        [[CometChat alloc]initWithAppId: appID appSettings:appSettings onSuccess:^(BOOL isSuccess) {
            NSLog(isSuccess ? @"CometChat Initialize Success:-YES" : @"CometChat Initialize Success:-NO");
        } onError:^(CometChatException * error) {
            NSLog(@"Error %@",[error errorDescription]);
        }];
        return YES;
    }
    ```
  </Tab>
</Tabs>

Make sure you replace the `appId` with your CometChat **App ID** in the above code.

| Parameter  | Description                         |
| ---------- | ----------------------------------- |
| appID      | CometChat App ID                    |
| appSetting | An object of the AppSettings class. |

***

## Publishing to App Store

To publish your App on App Store please [follow this guide](/sdk/ios/3.0/publishing-app-on-appstore)
