# Get Started

{% hint style="warning" %}
**Before you get started:** Make sure you have [**created a channel in OneTalk dashboard**](https://docs.taptalk.io/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/..#setup-live-chat-for-ios) and obtain the **`APP_KEY_SECRET.`**` `&#x20;
{% endhint %}

### Configure and Initialize TapTalk.io Omnichannel iOS SDK

#### Step 1: Install TapTalk.io Omnichannel iOS SDK

1. You can install the TapTalk.io Omnichannel iOS SDK using [CocoaPods](https://cocoapods.org/) like the following. If you are new to CocoaPods, you can see more information in [Cocoapods guides](https://guides.cocoapods.org/using/getting-started.html). To create a **Podfile**, open a terminal window, navigate to your project directory, and then create a **Podfile** by running the following command in the terminal:

```bash
$ pod init
```

Then **Podfile** will be created in your project directory. Open the **Podfile** and add the following lines to the **Podfile**.

```ruby
# Please make sure you define platform on your Podfile
# Make sure to use ios 11.0 for minimum deployment target

platform :ios, '11.0'

target "YourProjectName" do
    
    ...
    
    pod 'TapTalkLive'
    pod 'JSONModel', '1.8.0', :modular_headers => true
    
end
```

{% hint style="warning" %} <mark style="color:red;">**Note**</mark><mark style="color:red;">:</mark> <mark style="color:red;"></mark><mark style="color:red;">**For SDK version 1.1.0 and above,  remove**</mark><mark style="color:red;">**`use_frameworks!`**</mark><mark style="color:red;">**&#x20;**</mark><mark style="color:red;">**and add additional pod implementation with modular headers to handle some compatibility issues.**</mark>

For versions below 1.1.0, please remove **`pod 'JSONModel'`** implementation on the code above with **`use_frameworks!`**
{% endhint %}

{% hint style="warning" %}
**Note:** Please make sure you implement ios version 11.0`platform :ios, '11.0'` for minimum deployment target to obtain latest update of TapTalk.io SDK
{% endhint %}

Since TapTalk.io use uses **`git-lfs`** (Git Large Files Storage) you will need to install **GIT LFS** to clone/install TapTalk.io SDK through **Cocoapods**.

{% hint style="warning" %}
**Note**: Make sure to install **`git-lfs`**&#x62;efore pod install, otherwise the pod install / pod update will be error&#x20;
{% endhint %}

Easiest way to install [git-lfs](https://git-lfs.github.com) is using [brew](https://brew.sh):

{% tabs %}
{% tab title="Terminal" %}

```bash
brew install git-lfs
git lfs install
```

{% endtab %}
{% endtabs %}

Next, after the **`git-lfs`** is installed, install the TapTalk.io through CocoaPods.

```bash
$ pod install
```

#### Step 2: Grant permission in your application project

To make sure TapTalk.io Omnichannel iOS have all permission to access user's media, file, location, and contact, the application needs to ask for permissions. Go to your **info.plist**, and add the following key-value pairs.

| Information Property Key                            | Information Property Value                                                                                                                                                             |
| --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Privacy - Camera Usage Description                  | $(PRODUCT\_NAME) needs to request access to your camera to take profile picture and to send image chat.                                                                                |
| Privacy - Contacts Usage Description                | $(PRODUCT\_NAME) need your permission to access your contact, we will sync your contact to our server and automatically find your friend so it is easier for you to find your friends. |
| Privacy - Photo Library Additions Usage Description | $(PRODUCT\_NAME) needs to request access to your photo library to save photo.                                                                                                          |
| Privacy - Photo Library Usage Description           | $(PRODUCT\_NAME) needs to request access to your photo library to take profile picture and to send image chat.                                                                         |
| Privacy - Location When In Use Usage Description    | $(PRODUCT\_NAME) needs to request access to your location to send location chat.                                                                                                       |

{% hint style="info" %}
**Note**: You can change **Information Property Value** based on your own preferences. These values will appear when the application requests permission from the user.
{% endhint %}

![Adding new key in info.plist](https://4266585843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LfVupFSqh_qZAY9OiCO%2F-LzpjUyPVVETR4wSOgJn%2F-LzpjgZSXJKtiMFJ6Edq%2F8b43524-Screen_Shot_2019-08-28_at_13.57.43.png?alt=media\&token=f8fb75d2-8578-4456-ba53-0bda817a7a09)

![Adding new key in info.plist](https://4266585843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LfVupFSqh_qZAY9OiCO%2F-LzpjUyPVVETR4wSOgJn%2F-LzpjgZSXJKtiMFJ6Edq%2F8b43524-Screen_Shot_2019-08-28_at_13.57.43.png?alt=media\&token=f8fb75d2-8578-4456-ba53-0bda817a7a09)

#### Step 3: Enable background modes

Background modes is required to handle background process in TapTalk.io. It is used to run some processes in the background before the app is killed. For more information about the processes, check out the [background process section](https://docs.taptalk.io/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-ios/background-process-in-taptalklive-ios).

To enable **background modes**, go to **Target** -> **Capabilities**, then turn **Background Modes** toggle to **ON**, next select **Background fetch** and **Remote notifications**

![](https://4266585843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LfVupFSqh_qZAY9OiCO%2F-LzpjoPXCyDtXUTiNSXg%2F-Lzpk4nGaQ8fBhUqHqNN%2Feaab744-Screen_Shot_2019-08-28_at_13.37.54.png?alt=media\&token=7a41a275-97e7-48aa-a11a-ee283d9ac68e)

After you turn on the **Background Modes**, **Required background modes** key will be added automatically in your **Info.plist** as shown below.

![](https://4266585843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LfVupFSqh_qZAY9OiCO%2F-LzpjoPXCyDtXUTiNSXg%2F-LzpkK_5kgOcDdlpGK5k%2F979a00b-Screen_Shot_2019-08-28_at_13.44.36.png?alt=media\&token=3da5a3ec-927b-461a-98b7-626c3ac5a7f7)

#### Step 4: Initialize TapTalk.io Omnichannel Application Delegate

To allow the iOS SDK to respond to the connection and state changes in your iOS client app, you have to implement all of our application delegate methods in your **`UIApplicationDelegate`** methods in appDelegate file.

After you initialize the TapTalk.io Omnichannel, you have to connect and implement these methods in your **`UIApplicationDelegate`** methods in **appDelegate** file to make sure TapTalk.io Omnichannel runs smoothly in your application.

| TapTalk.io Omnichannel Application Delegate Method | Description                                                                                   |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `application:didFinishLaunchingWithOptions:`       | Tells the delegate that the launch process is almost done and the app is almost ready to run. |
| `applicationWillResignActive:`                     | Tells the delegate that the app is about to become inactive.                                  |
| `applicationDidEnterBackground:`                   | Tells the delegate that the app is now in the background.                                     |
| `applicationWillEnterForeground:`                  | Tells the delegate that the app is about to enter the foreground.                             |
| `applicationDidBecomeActive:`                      | Tells the delegate that the app has become active.                                            |
| `applicationWillTerminate:`                        | Tells the delegate when the app is about to terminate.                                        |
| `handleException:`                                 | Tells the delegate when application throws exception.                                         |

{% code title="AppDelegate.m" %}

```csharp
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
    //Implement TapTalk Omnichannel didFinishLaunchingWithOptions here    
    [[TapTalkLive sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    
    //Other code
    ...
    
    return YES;
}
```

{% endcode %}

{% code title="AppDelegate.m" %}

```csharp
- (void)applicationWillResignActive:(UIApplication *)application {
  
    //Implement TapTalk Omnichannel applicationWillResignActive here
    [[TapTalkLive sharedInstance] applicationWillResignActive:application];
  
    //Other code
    ...
}
```

{% endcode %}

{% code title="AppDelegate.m" %}

```csharp
- (void)applicationDidEnterBackground:(UIApplication *)application {
    //Implement TapTalk Omnichannel applicationDidEnterBackground here
    [[TapTalkLive sharedInstance] applicationDidEnterBackground:application];
  
    //Other code
    ...
}
```

{% endcode %}

{% code title="AppDelegate.m" %}

```csharp
- (void)applicationWillEnterForeground:(UIApplication *)application {
  
    //Implement TapTalk Omnichannel applicationWillEnterForeground here
    [[TapTalkLive sharedInstance] applicationWillEnterForeground:application];
  
    //Other code
    ...
  }
```

{% endcode %}

{% code title="AppDelegate.m" %}

```csharp
- (void)applicationDidBecomeActive:(UIApplication *)application {
  
    //Implement TapTalk Omnichannel applicationDidBecomeActive here    
    [[TapTalkLive sharedInstance] applicationDidBecomeActive:application];
  
    //Other code
    ...
}
```

{% endcode %}

{% code title="AppDelegate.m" %}

```csharp
- (void)applicationWillTerminate:(UIApplication *)application {
  
    //Implement TapTalk Omnichannel applicationWillTerminate here
    [[TapTalkLive sharedInstance] applicationWillTerminate:application];
  
    //Other code
    ...
}
```

{% endcode %}

You have to add below code `NSSetUncaughtExceptionHandler(&handleExceptions);` in `application:didFinishLaunchingWithOptions:`method to register uncaught exception handler and add delegate function `handleExceptions`.

<pre class="language-csharp" data-title="AppDelegate.m"><code class="lang-csharp">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Register Uncaught Exception Handler
    NSSetUncaughtExceptionHandler(&#x26;handleExceptions);
}

// Add delegate function to handle exceptions
- (void)handleExceptions:(NSException *exception) {
    // Implement TapTalk Omnichannel handleException method
<strong>    [[TapTalkLive sharedInstance] handleException:exception];
</strong>}
</code></pre>

{% hint style="warning" %}
**Note**: Don't forget to register for exception handler inside **`application:didFinishLaunchingWithOptions:`**&#x6D;ethod and implement **`handleExceptions`** method in **appDelegate** class to make sure TapTalk.io able to handle exceptions.
{% endhint %}

#### Step 5: Initialize TapTalk.io Omnichannel iOS in your application class

In order to use TapTalk.io Omnichannel, you must first initialize an instance by passing the `APP_KEY_SECRET` and `API_BASE_URL` assigned to your application to the `initWithSecretKey:` method as a parameter. Generally, initialization is implemented in the **appDelegate** `application:didFinishLaunchingWithOptions:` method.

{% code title="AppDelegate.m" %}

```csharp
// Import TapTalk.io Omnichannel
#import <TapTalkLive/TapTalkLive.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\
    [[TapTalkLive sharedInstance] initWithSecretKey:APP_KEY_SECRET
    success:^{
        // Succcessfully initialized TapTalkLive
    }
    failure:^(NSString *errorMessage) {
        
    }];
}

...

@end
```

{% endcode %}

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`APP_KEY_SECRET`**: (String) application key Secret
{% endhint %}

To allow the Omnichannel iOS SDK to respond to the connection and state changes in your iOS client app, you have to implement all of our application delegate methods in your UIApplicationDelegate methods in appDelegate file. You can follow the instructions in [Implement Application Delegate page](https://docs.taptalk.io/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-ios/broken-reference).

### Initialize Google Places API Key (Optional)

To enable location search result preview while sending location message, a Google Places API Key is required. To obtain the API key for your application, you can check [the documentation](https://developers.google.com/places/web-service/get-api-key) provided by Google. To initialize, insert your obtained key using the `initializeGooglePlacesApiKey()` method.

```csharp
#import <TapTalkLive/TapTalkLive.h>
  
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    //Initialize Google Places API Key
    [[TapTalkLive sharedInstance] initializeGooglePlacesAPIKey:GOOGLE_PLACES_API_KEY]; 
}
```

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`GOOGLE_PLACES_API_KEY`**: (String) Google Places API key
{% endhint %}

### Open TapTalk.io Omnichannel View

To open TapTalk Omnichannel's view UI for your application, you can use the **`presentTapTalkLiveViewWithCurrentNavigationController:animated`** or **`pushTapTalkLiveViewWithCurrentNavigationController:animated`** method from the **TapTalkLive** class. This will open a homepage view controller containing a list of available channels, the user's latest case, and QnA path.

```csharp
#import <TapTalkLive/TapTalkLive.h>

/**
Called to show TapTalk Live view with present animation

 @param navigationController (UINavigationController *) your current navigation controller
 @param animated (BOOL) make the present animated or not
*/
[[TapTalkLive sharedInstance] presentTapTalkLiveViewWithCurrentNavigationController:NAVIGATION_CONTROLLER animated:ANIMATED];

/**
Called to show TapTalk Live view with push animation

 @param navigationController (UINavigationController *) your current navigation controller
 @param animated (BOOL) make the present animated or not
*/
[[TapTalkLive sharedInstance] pushTapTalkLiveViewWithCurrentNavigationController:NAVIGATION_CONTROLLER animated:ANIMATED];
```

{% hint style="info" %}
**Parameters**\
\&#xNAN;**`NAVIGATION_CONTROLLER`**: (UINavigationController) your current active navigation controller\
\&#xNAN;**`ANIMATED`**: (BOOL) boolean to state animation active or not
{% endhint %}
