# Get Started - iOS

## Quick Start

TapTalk.io helps you to implement real-time chat with any type of your client app with speed and efficiency. Our iOS SDK provides you with various methods to initialize, configure, and build the chat from the client-side - no server-side implementation is required because our reliable infra management service is delivered with the SDK. This page presents a brief overview of the SDK’s structure and abilities, then lets you go through the preliminary steps of implementing the SDK in your own app. We will be using **Xcode** for the native side implementation.

## Configure and Initialize TapTalk.io iOS SDK

#### **Step 1: Create a new application from your dashboard**

**1.** Login to [TapTalk.io Dashboard](https://taptalk.io/), then choose **Development** -> **Apps**

![](/files/-MHKvQJYwokZj2SvRd6U)

**2**. Click **New App** Button, input **App Name** and choose **Platform**, and then click **Create New App** Button.

![](/files/-MHKxC_cD1-kv3lPxiSk)

![](/files/-MHKxGJV7RBtqLBu8UwT)

**3.** A pop-up dialog will be shown with provided **App Key ID** & **App Key Secret**

![](/files/-MHKxQLyhxLOunGM05hx)

{% hint style="warning" %}
**Note:** Please remember to save your **App Key ID** & your **App Key Secret** because it will only be shown once and will be used in TapTalk.io initialization
{% endhint %}

#### Step 2: Install TapTalk.io SDK

You can install the PowerTalk 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 'TapTalk'
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><tr><td>Privacy - Microphone Usage Description</td><td>$(PRODUCT_NAME) needs to request access to your microphone to record audio to send voice 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, we can 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](/powertalk-chat-sdk-documentation/powertalk-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. `openPowerTalkUI()` function to open the chat room list view
3. A button to call the `openPowerTalkUI()` function

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

```dart
class _MyHomePageState extends State<MyHomePage> {
  
  // Create the MethodChannel
  static const powerTalkMethodChannel = MethodChannel('io.taptalk.powertalk');
  
  // Function to open the chat room list UI
  Future<void> _openPowerTalkUI() async {
    try {
      // Initialize PowerTalk SDK
      final bool isPowerTalkInitialized = await powerTalkMethodChannel.invokeMethod('initPowerTalk');
      if (isPowerTalkInitialized) {
        // Authenticate PowerTalk SDK
        final bool isPowerTalkAuthenticated = await powerTalkMethodChannel.invokeMethod('authPowerTalk');
        if (isPowerTalkAuthenticated) {
          // Open chat room list
          await powerTalkMethodChannel.invokeMethod('openChatRoomList');
        }
      }
    }
    on PlatformException catch (e) {
      print(e.message);
    }
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      ...
      body:
        ...
          // Sample button to call openPowerTalkUI
          ElevatedButton(
            onPressed: _openPowerTalkUI,
            child: Text(
              'Get Started with PowerTalk',
            ),
          ),
      ...
    );
  }
}
```

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

Please note the name parameter in the MethodChannel constructor that was used (`io.taptalk.powertalk`), and the method name in the `invokeMethod()` parameter (`initPowerTalk`, `authPowerTalk` & `openChatRoomList`). 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 PowerTalk SDK and open the chat room list view

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

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

@interface AppDelegate () <TapTalkDelegate>

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

@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 *powerTalkMethodChannel = [FlutterMethodChannel methodChannelWithName:@"io.taptalk.powertalk"
                                                                               binaryMessenger:controller.binaryMessenger];

    // Handle MethodChannel calls
    [powerTalkMethodChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
        // Save result to variable
        self->_powerTalkMethodChannelResult = result;
        
        // Call native methods
        if ([call.method isEqualToString:@"initPowerTalk"]) {
            [self initPowertalk];
        }
        else if ([call.method isEqualToString:@"authPowerTalk"]) {
            [self authenticatePowertalk];
        }
        else if ([call.method isEqualToString:@"openChatRoomList"]) {
            [self openChatRoomList];
        }
        else {
            result(FlutterMethodNotImplemented);
        }
    }];
    
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

// Method to initialize PowerTalk SDK
- (void)initPowertalk {
    [[TapTalk sharedInstance] initWithAppKeyID:POWERTALK_APP_KEY_ID
                                  appKeySecret:POWERTALK_APP_KEY_SECRET
                                  apiURLString:POWERTALK_APP_BASE_URL
                            implementationType:TapTalkImplentationTypeCombine];
    
    if (self.powerTalkMethodChannelResult != nil) {
        self.powerTalkMethodChannelResult(@(YES));
    }
}

// Method to authenticate PowerTalk SDK
- (void)authenticatePowertalk {
    [[TapTalk sharedInstance] authenticateWithAuthTicket:ticket
                                      connectWhenSuccess:YES
    success:^{
        if (self.powerTalkMethodChannelResult != nil) {
            self.powerTalkMethodChannelResult(@(YES));
        }
    }
    failure:^(NSError * _Nonnull error) {
        if (self.powerTalkMethodChannelResult != nil) {
            self.powerTalkMethodChannelResult([FlutterError errorWithCode:[@(error.code) stringValue]
                                                                  message:error.localizedDescription
                                                                  details:nil]);
        }
    }];
}

// Method to open chat room list view
- (void)openChatRoomList {
    TapUIRoomListViewController *roomListViewController = [[TapUI sharedInstance] roomListViewController];
    UINavigationController *roomListNavigationController = [[UINavigationController alloc] initWithRootViewController:roomListViewController];
    roomListNavigationController.modalPresentationStyle = UIModalPresentationOverFullScreen;
    
    UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    
    [rootViewController presentViewController:roomListNavigationController animated:YES completion:^{
        if (self.powerTalkMethodChannelResult != nil) {
            self.powerTalkMethodChannelResult(@(YES));
        }
    }];
}
```

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

{% hint style="info" %}
You can obtain **POWERTALK\_AUTH\_TICKET** by following the guide in [Authentication  page](/powertalk-chat-sdk-documentation/powertalk-ios/authentication.md).
{% endhint %}

#### Step 8: Implement 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. You can follow the instructions in [Implement Application Delegate page](/powertalk-chat-sdk-documentation/powertalk-ios/implement-application-delegate.md).

{% hint style="info" %}
**Note**: In the [Event Delegate](/powertalk-chat-sdk-documentation/powertalk-ios/event-delegate.md) page, you can find detailed information on the usages of TapTalk iOS SDK's delegates and callbacks.
{% endhint %}

You can now try running the app. Pressing the sample button will invoke the `openPowerTalkUI` method that we previously created, which will initialize & authenticate PowerTalk SDK, and open the chat room list view once the initialization is completed. You may also try a different implementation and separate the **init**, **authenticate**, 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 [PowerTalk iOS](/powertalk-chat-sdk-documentation/powertalk-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/powertalk-chat-sdk-documentation/powertalk-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.
