Get Started - iOS
This section will cover a step-by-step approach to bridge your Flutter project to OneTalk Live Chat iOS SDK. We will be using Xcode to configure native code in Flutter project.
Before you get started: Make sure you have created a channel in OneTalk dashboard and obtain the APP_KEY_SECRET.
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 like the following. If you are new to CocoaPods, you can see more information in Cocoapods guides. 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:
Then Podfile will be created in your project directory. Open the Podfile and add the following lines to the Podfile.
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.
Note: Make sure to install git-lfs
before pod install, otherwise the pod install / pod update will return an error
Easiest way to install git-lfs is using brew:
Next, after the git-lfs
is installed, install the TapTalk.io SDK through CocoaPods.
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:
Then open the Release.xcconfig file and add the following lines:
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.
Note: You can change Information Property Value with your preferred message, the string value will be displayed when the application requests the permission.
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. To enable background modes, go to Target -> Capabilities, then turn Background Modes toggle to ON, next select Background fetch and Remote notifications
After you turn on the Background Modes, Required background modes key will be added automatically in your Info.plist as shown below.
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, you can skip to the next step.
In this example, we will add the following inside the MyHomePageState class:
Method Channel to connect to the native iOS host
openOneTalkLiveChatTalkUI()
function to open the Live Chat's viewA button to call the
openOneTalkLiveChatTalkUI()
function
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
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:
Add a MethodChannel Result variable to handle asynchronous call
setMethodCallHandler to handle calls from the MethodChannel that we previously created.
Add native functions to initialize & authenticate OneTalk Live Chat SDK and open the chat room list view
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.
Note: Don't forget to register for exception handler inside application:didFinishLaunchingWithOptions:
method and implement handleExceptions
method in appDelegate class to make sure TapTalk.io Omnichannel SDK is able to handle exceptions.
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.
Note: You can check a more complete implementation guide in the OneTalk Live Chat for iOS section.
Last updated