# Get Started - iOS

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

### Configure and Initialize TapTalk.io Omnichannel iOS SDK for Flutter project

#### Step 1: Install TapTalk.io Omnichannel iOS SDK **with CocoaPods**

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). First, navigate to the **ios** folder of your Flutter project directory, and check if a file named **Podfile** exists. If there is no **Podfile** in the **ios** folder, we will create a new one using terminal. Open a terminal window and navigate to the **ios** directory of your Flutter project, then create a **Podfile** by running the following command in the terminal:

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

```bash
$ pod init
```

{% endtab %}
{% endtabs %}

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

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

```ruby
# If you specified a platform for your project,
# please make sure to use ios 11.0 for minimum deployment target
platform :ios, '11.0'
use_frameworks!

target "YourProjectName" do
    pod 'TapTalkLive'
end
```

{% endtab %}
{% endtabs %}

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 return an error
{% 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 SDK through CocoaPods.

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

```bash
$ pod install
```

{% endtab %}
{% endtabs %}

#### Step 3: Include Pods Runner in xcconfig

After the pod is successfully installed, we will handle the implementation in the native side using **Xcode**. Open the **xcworkspace** file in your project's **ios** folder. (The default project name for iOS should be Runner, in this case, open Runner.xcworkspace).

If you previously created a new Podfile in the **ios** folder, open **Debug.xcconfig** file under the Flutter folder (you can also press *Cmd + Shift + O* to search by file name) and add the following:

{% tabs %}
{% tab title="Debug.xcconfig" %}

```objectivec
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
```

{% endtab %}
{% endtabs %}

Then open the **Release.xcconfig** file and add the following lines:

{% tabs %}
{% tab title="Release.xcconfig" %}

```objectivec
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"
```

{% endtab %}
{% endtabs %}

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

To make sure TapTalk.io has all permission to access the user's media, file, location, and contact, the application needs to ask for permission. Open the **info.plist** file under the Runner folder, and add the following key-value pairs.

<table data-header-hidden><thead><tr><th width="339">Information Property Key</th><th>Information Property Value</th></tr></thead><tbody><tr><td><strong>Information Property Key</strong></td><td><strong>Information Property Value</strong></td></tr><tr><td>Privacy - Camera Usage Description</td><td>$(PRODUCT_NAME) needs to request access to your camera to send image messages and take profile picture.</td></tr><tr><td>Privacy - Contacts Usage Description</td><td>$(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.</td></tr><tr><td>Privacy - Photo Library Additions Usage Description</td><td>$(PRODUCT_NAME) needs to request access to your photo library to save photos.</td></tr><tr><td>Privacy - Photo Library Usage Description</td><td>$(PRODUCT_NAME) needs to request access to your photo library to send image messages and select profile picture.</td></tr><tr><td>Privacy - Location When In Use Usage Description</td><td>$(PRODUCT_NAME) needs to request access to your location to send location messages.</td></tr></tbody></table>

{% hint style="info" %}
**Note:** You can change **Information Property Value** with your preferred message, the string value will be displayed when the application requests the permission.
{% endhint %}

![](/files/-MHLISj3JHnpzjIeKv5r)

#### Step 5: 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](/powertalk-chat-sdk-documentation/powertalk-ios/background-process-in-taptalk.io.md).\
To enable **background modes**, go to **Target** -> **Capabilities**, then turn **Background Modes** toggle to **ON**, next select **Background fetch** and **Remote notifications**

![](/files/-MHLIm1-VkzIwjxQilqS)

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

![](/files/-MHLItjSE_HAsYniTXmS)

After adding the required dependency, sync your project and begin the next step by writing custom platform-specific code using platform channels.

#### Step 6: Create Flutter Platform Client

If you have finished this step from the [Android side](/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-live-chat-for-flutter/get-started-android.md#step-3-create-flutter-platform-client), you can skip to the [next step](#step-3-add-an-android-platform-specific-implementation).

In this example, we will add the following inside the MyHomePageState class:

1. Method Channel to connect to the native iOS host
2. `openOneTalkLiveChatTalkUI()` function to open the Live Chat's view
3. A button to call the `openOneTalkLiveChatTalkUI()` function

{% tabs %}
{% tab title="First Tab" %}
{% code title="main.dart" %}

```dart
class _MyHomePageState extends State<MyHomePage> {
  
  // Create the MethodChannel
  static const oneTalkLiveChatMethodChannel = MethodChannel('io.taptalk.onetalklivechat');
  
  // Function to open the live chat view
  Future<void> _openOneTalkLiveChatTalkUI() async {
    try {
      // Initialize OneTalk Live Chat SDK
      final bool isOneTalkInitialized = await oneTalkLiveChatMethodChannel.invokeMethod('initOneTalkLiveChat');
      if (isOneTalkInitialized) {
        // Open live chat view
        await oneTalkLiveChatMethodChannel.invokeMethod('openLiveChatView');
      }
    }
    on PlatformException catch (e) {
      // Call might fail if the platform doesn’t support the platform API
      print(e.message);
    }
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      ...
      body:
        ...
          // Sample button to call openOneTalkLiveChatTalkUI
          ElevatedButton(
            onPressed: _openOneTalkLiveChatTalkUI,
            child: Text(
              'Get Started with OneTalk Live Chat',
            ),
          ),
      ...
    );
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

Please note the name parameter in the MethodChannel constructor that was used (`io.taptalk.onetalklivechat`), and the method name in the `invokeMethod()` parameter (`initOneTalkLiveChat` & `openLiveChatView`). We will use the same names later to configure Flutter engine in the native side.

#### Step 7: Add an iOS platform-specific implementation <a href="#step-3-add-an-android-platform-specific-implementation" id="step-3-add-an-android-platform-specific-implementation"></a>

Next, we will configure the native side of the iOS host implementation. Go back to previously opened Xcode project, and open **AppDelegate.m** file. We will do the following:

1. Add a MethodChannel Result variable to handle asynchronous call
2. setMethodCallHandler to handle calls from the MethodChannel that we previously created.
3. Add native functions to initialize & authenticate OneTalk Live Chat SDK and open the chat room list view

{% tabs %}
{% tab title="Objective-C" %}

<pre class="language-csharp" data-title="AppDelegate.m"><code class="lang-csharp">// Import TapTalkLive
#import &#x3C;TapTalkLive/TapTalkLive.h>

@interface AppDelegate () &#x3C;TapTalkLiveDelegate>

// MethodChannel Result to handle asynchronous call
@property (nonatomic) FlutterResult oneTalkMethodChannelResult;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
    [GeneratedPluginRegistrant registerWithRegistry:self];
  
    // Override point for customization after application launch.
    
    FlutterViewController *controller = (FlutterViewController *) self.window.rootViewController;
    
    // Create MethodChannel
    FlutterMethodChannel *oneTalkMethodChannel = [FlutterMethodChannel methodChannelWithName:@"io.taptalk.onetalklivechat"
                                                                             binaryMessenger:controller.binaryMessenger];
    // Handle MethodChannel calls
    [oneTalkMethodChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
<strong>        // Save result to variable
</strong><strong>        self->_oneTalkMethodChannelResult = result;
</strong>        
        // Call native methods
        if ([call.method isEqualToString:@"initOneTalkLiveChat"]) {
            [self initOneTalkLiveChat];
        }
        else if ([call.method isEqualToString:@"openLiveChatView"]) {
            [self openLiveChatView];
        }
        else {
            result(FlutterMethodNotImplemented);
        }
    }];
    
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

// Method to initialize OneTalk Live Chat SDK
- (void)initOneTalkLiveChat {
    [[TapTalkLive sharedInstance] initWithSecretKey:ONETALK_APP_KEY_SECRET
    success:^{
        if (self.oneTalkMethodChannelResult != nil) {
            self.oneTalkMethodChannelResult(@(YES));
        }
    }
    failure:^(NSString *errorMessage) {
        if (self.oneTalkMethodChannelResult != nil) {
            self.oneTalkMethodChannelResult([FlutterError errorWithCode:YOUR_ERROR_CODE
                                                                message:errorMessage
                                                                details:nil]);
        }
    }];
}

// Method to open live chat view
- (void)openLiveChatView {
    UINavigationController *rootNavigationController = (UINavigationController *) [UIApplication sharedApplication].keyWindow.rootViewController;
    [[TapTalkLive sharedInstance] presentTapTalkLiveViewWithCurrentNavigationController:rootNavigationController animated:YES];
    if (self.oneTalkMethodChannelResult != nil) {
        self.oneTalkMethodChannelResult(@(YES));
    }
}
</code></pre>

{% endtab %}
{% endtabs %}

#### Step 8: 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.                                         |

{% tabs %}
{% tab title="Objective-C" %}
{% code title="AppDelegate.m" %}

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

// Implement TapTalkLiveDelegate
@interface AppDelegate () <TapTalkLiveDelegate>

// Properties
...

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
    // Implement TapTalk Omnichannel didFinishLaunchingWithOptions here    
    [[TapTalkLive sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    
    // Register Uncaught Exception Handler
    NSSetUncaughtExceptionHandler(&handleExceptions);
    
    // Other code
    ...
    
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

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

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

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

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

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

// Add function to handle exceptions
- (void)handleExceptions:(NSException *exception) {
  // Implement TapTalk Omnichannel handleException method
  [[TapTalkLive sharedInstance] handleException:exception];
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% 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 Omnichannel SDK is able to handle exceptions.
{% endhint %}

You can now try running the app. Pressing the sample button will invoke the `openOneTalkLiveChatTalkUI()` method that we previously created, which will initialize OneTalk Live Chat SDK, and open the live chat view once the initialization is completed. You may also try a different implementation and separate the **init** and the **open view** methods. You can also add more calls to other native methods with the same approach using the same MethodChannel.

{% hint style="info" %}
**Note**: You can check a more complete implementation guide in the [OneTalk Live Chat for iOS](/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-ios.md) section.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.taptalk.io/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-live-chat-for-flutter/get-started-ios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
