Orange Chat iOS SDK

Webcom is the Orange Backend-as-a-Service / Serverless solution.

Webcom provides integrated functions of database and messages exchange platforms, authentication aggregation, data exposure and access control. This platform drastically reduce time and cost to implement and deploy mobile, web or IoT applications in production.

Table of Contents

1. Create a Orange Chat Application

  1. Sign up/in on Webcom console
  2. Add an application with the identifier of your choice, e.g. ChatDirectory

2. Setup you Swift Project

2.1. Integrate the Orange Chat Framework

2.1.1. Using Swift Package Manager

Swift Package Manager integration uses source code which will be compiled on your computer.

In your Package.swift file, add the following dependency:

let package = Package(
    ...
    dependencies: [
        ...
        .package(name: "OrangeChat", url: "ssh://git@gitlab.tech.orange:webcom/ochat/sdk-ios.git", .upToNextMajor(from: "1.0.0-beta.2")),
    ],
    ...
    targets: [
        ...
        .target(
            ...
            dependencies: [
                ...
                .product(name: "OrangeChat", package: "OrangeChat"),
            ],
            ...
        ),
        ...
    ]
)

2.2. Add Webcom Configuration in Info.plist

In your Info.plist file, add a Webcom property as follows:

Key Type Value Description
▼ Webcom Dictionary root key for Webcom parameters
identifier String ChatDirectory identifier of the Webcom application

3. Start Coding

Orange Chat SDK is written user Swift 5.5 and rerquires at least Xcode 13.

3.1. Import OrangeChat Module

import OrangeChat

3.2. Orange Chat Manager

All of the SDK tools are accessible from a OrangeChatManager instance. This instance is an environment object variable of the application.

3.2.1. Using an environment object variable

@EnvironmentObject var orangeChatManager: OrangeChatManager

3.3. Authentication

The Authentication makes it possible to reliably identify users of applications, in order to finely control their access to data.

Instantiate the Authentication of the application:

let authentication = orangeChatManager.authentication

Authenticate using a One Time Password sent by SMS:

authentication.requestOtpSMS(for: "+33699935239")
authentication.login(withOTP: "1234")

Authenticate using a custom provider:

authentication.login(withProvider: "foo", and: "fooCredentials", for: "+33699935239")

3.4. Room List

The RoomList allows to manage all the operations on a list of rooms (creation, real time listing, deletion…).

Instantiate a RoomList of the application:

let roomList = orangeChatManager.roomList

3.5. Room

The Room allows to manage all the operations on a list of rooms (sending and receiving messages in real time, typing indicator…).

Instantiate a Room of the application:

let room = roomList.room(with:)

3.6. Orange Chat Notification Manager

The SDK has its own management of push notifications for new message or new invitation events. For this to work, the SDK needs to share information between the main application and the NotificationService extension. Thereby, they must have a common App Group, configured in their respective Signing & Capabilities configuration tabs.

Configure chat push notifications in the AppDelegate:

import Firebase
import OrangeChat

// Make the AppDelegate conforms to `OrangeChatNotificationManager` and `MessagingDelegate`
class AppDelegate: OrangeChatNotificationManager, UIApplicationDelegate, MessagingDelegate {

    // Complete the application(_:didFinishLaunchingWithOptions:) method:
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        Messaging.messaging().delegate = self
        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
        application.registerForRemoteNotifications()
        configure(groupName: "group.XXX.YYY.ZZZ") // Same value as in `didReceive(_:withContentHandler:)` of `NotificationService`
        return true
    }

    // Add the following override method of `OrangeChatNotificationManager` in the `AppDelegate`:
    override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        Messaging.messaging().appDidReceiveMessage(response.notification.request.content.userInfo)
        super.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
        completionHandler()
    }

    // Add the following method in the AppDelegate:
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken firebaseMessagingToken: String?) {
        deviceToken = firebaseMessagingToken
    }
}

Configure the process of chat push notifications in NotificationService:

import UserNotifications
import OrangeChat

// Make the NotificationService conforms to `OrangeChatNotificationManager`
class NotificationService: OrangeChatNotificationManager {

    // Add the folowing override method of `OrangeChatNotificationManager` in the `NotificationService`:
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        configure(groupName: "group.XXX.YYY.ZZZ") // Same value as in `application(_:didFinishLaunchingWithOptions:)` of `AppDelegate`
        super.didReceive(request, withContentHandler: contentHandler)
    }
}

You may be interested by the following type: OrangeChatNotificationManager.

4. State of the art

All the features listed below are taken from the chat data model.

4.1. Developed features

  • SMS Authentication
  • Custom Authentication
  • Deauthentication
  • Creation of chat rooms between two people
  • Display of chat rooms of a current user with real-time updating
  • Hiding a chat room
  • Sending and receiving messages in a conversation between two users
  • Display of messages from a conversation of a current user with real-time updating
  • Notification of writing a message in real-time
  • Application and conversation presence mechanism
  • Push notifications for new messages and new invitation

4.2. Not yet developed features

  • Video, audio and image message
  • Group chat
  • Management of the events of a chat room
  • Checking the SDK version with Webcom
  • Message status
  • Conversation avatar
  • Bot management

5. More Information