IOS SDK

Overview

eRTC SDK is a fully featured enterprise solution for instant messaging framework for iOS. eRTC SDK is fully featured, scalable and flexible and follows the following key principles:

Enterprise solutions
Full data control
Quick integration
Firebase Powered by Google Firebase

Features

Individual messages
Push notifications
Text, Image,Video,Audio messages
Typing Indicators.
Delivered and Read receipts.
Chat history
Chat user list
Contact details
Encryption

Quickstart

API Documentation
Code Examples

Adding the Chat SDK to your project

Add the eRTC SDK development pods to your Podfile.

use_frameworks!
       pod “eRCTSDK”

Run pod install to get the latest version of the code.

Run pod update to get the latest version of the code (optional for pod update).

Open the App Delegate add the following code to initialise the chat

Objective C

AppDelegate.m -> application: didFinishLaunchingWithOptions:

#import <eRTC/eRTCSDK.h>

Add the following code to the start of your didFinishLaunchingWithOptions function:

[eRTCSDK initialise];

Swift

AppDelegate.m -> application: didFinishLaunchingWithOptions:

import <eRTC/eRTC.h>

Add the following code to the start of your didFinishLaunchingWithOptions function:

eRTCSDK.initialize()

Validate the namespace

Objective C

[eRTCSDK validateNameSpaceWithWorkSpaceName:@”www.sampleeRTC.com”
withSuccess:^(BOOL isValid,NSString *errMsg) {
   NSLog(@“Response—> %@", isValid);

}
andFailure:^(NSError *error) {
   NSLog(@"error”—> %@", [error localizedDescription]);
}];

Swift

eRTCSDK.validateNameSpace(withWorkSpaceName:
"sample.ertc.com", withSuccess: { (isValid, Bool) in
print("respones",isValid)
}) { (Error) in
print("Error",Error!)
}

Login with user details

Objective C

NSDictionary *dictParam = @{
   @"loginType": userName,
   @"appUserId": @“user email”,
   @"password": @“user password”
};

[[eRTCUserAuthentication sharedInstance]
userAuthenticationWithParam:dictParam andCompletion:
^(id _Nonnull json, NSString * _Nonnull errMsg) {
            NSLog(@“Response—> %@",json);

     } andFailure:^(NSError * _Nonnull error) {
}];

Swift

let dictParam = ["loginType": "userName", "appUserId":
"sample@gmail.com","password": "123456"];
eRTCUserAuthentication.sharedInstance().userAuthentication(
withParam: dictParam, andCompletion: { (json, String) in
print("respones",json) }) { (Error) in
print("Error",Error)
}

Forgot Password

Objective C

NSDictionary *dictParam = @{
   @"loginType": userName, @"appUserId": @“user email”
};

[[eRTCUserAuthentication sharedInstance]
   forgotPasswordWithParam:dictParam andCompletion:
   ^(id _Nonnull json, NSString * _Nonnull errMsg) {


   } andFailure:^(NSError * _Nonnull error) {
}];

Swift

let dictParam = ["loginType": "userName", "appUserId": "sample@gmail.com"];
eRTCUserAuthentication.sharedInstance().forgotPassword(withParam: dictParam, andCompletion: { (json, String) in
print("respones",json)})
{ (Error) in
print("Error",Error)
}

Change Password

Objective C

NSDictionary *dictParam = @{
   @"loginType": userName,
   @"appUserId": appUserID,
   @"currentPassword": @"",
   @"newPassword": @""
};

[[eRTCUserAuthentication sharedInstance]
   changePasswordWithParam:dictParam andCompletion:
   ^(id _Nonnull json, NSString * _Nonnull errMsg) {


   } else {

   }
} andFailure:^(NSError * _Nonnull error) {
}];

Swift

let dictParam = ["loginType": "userName","appUserId":
"appUserID","currentPassword":"123456","newPassword":
"098765 "]

eRTCUserAuthentication.sharedInstance().changePassword(
withParam: dictParam, andCompletion: { (json, String) in
print("respones",json)})
{ (Error) in
print("Error",Error)
}

Get Chat Users List

Objective C

[[eRTCCoreDataManager sharedInstance]
fetchChatUserListWithCompletionHandler:^(id ary, NSError *err) {

   NSLog(@"array of chatUser--> %@",ary);

}];

Swift

eRTCCoreDataManager.sharedInstance().fetchChatUserList(completionHandler: { ary, err in
if let ary = ary {
print("arrUser--> \(ary)")
}
})

Create Chat Thread

Objective C

To initiate chat , you have to create thread with the recipient For example when you select any user need to call thread api.

[[eRTCChatManager sharedChatInstance]
   getChatThreadIDWithParam:[NSDictionary dictionaryWithDictionary:dictParam] andCompletion:
   ^(id _Nonnull json, NSString * _Nonnull errMsg) {

      NSLog(@“Response—> %@",json);

   } andFailure:^(NSError * _Nonnull error) {

      NSLog(@"error threadId %@",error);
}];

Swift

let dictParam = ["appUserId": "appUserId"]

eRTCChatManager.sharedChatInstance().getChatThreadID(
withParam: dictParam, andCompletion: { (json, String) in
print("respones",json)})
{ (Error) in
print("Error",Error)
}

Send Text Message

Objective C

NSMutableDictionary * dictParam = [NSMutableDictionary new];
   [dictParam setObject:@“” forKey:@“SendereRTCUserId”];
   [dictParam setObject:@“” forKey:@“Message”];
   [dictParam setObject:@“” forKey:ThreadID];

[[eRTCChatManager sharedChatInstance]
   sendTextMessageWithParam:[NSDictionary dictionaryWithDictionary:dictParam] andCompletion:
   ^(id _Nonnull json, NSString * _Nonnull errMsg) {
      NSLog(@“Response—> %@",json);

 &NSLog(@"error--> %@",error);
}];

Swift

let dictParam = ["appUserId":
"appUserId","threadId":"threadId","message":"message"]
eRTCChatManager.sharedChatInstance().sendTextMessage(
withParam: dictParam, andCompletion: { (json, String) in
print("respones",json)})
{ (Error) in
print("Error",Error)
}

Send Image Message

Objective C

NSMutableDictionary * dictParam = [NSMutableDictionary new];
[dictParam setObject:userId forKey:SendereRTCUserId];
[dictParam setObject:@“” forKey:ThreadID];

[[eRTCChatManager sharedChatInstance]
   sendPhotoMediaItemWithParam:dictParam andFileData:data
];

Swift

let dictParam = ["appUserId":"appUserId","threadId":"threadId"]

eRTCChatManager.sharedChatInstance().sendPhotoMediaItem(
withParam: dictParam, andFileData: data! as Data)

Send Audio Message

Objective C

NSMutableDictionary * dictParam = [NSMutableDictionary new];
[dictParam setObject:userId forKey:SendereRTCUserId];
[dictParam setObject:self.strThreadId forKey:ThreadID];

[[eRTCChatManager sharedChatInstance]
   sendAudioMediaItemWithParam:dictParam andFileData:data
];

Swift

let dictParam =
["appUserId":"appUserId","threadId":"threadId"]
eRTCChatManager.sharedChatInstance().sendAudioMediaItem(
withParam: dictParam, andFileData: data! as Data)

Send Video Message

Objective C

NSMutableDictionary * dictParam = [NSMutableDictionary new];
[dictParam setObject:userId forKey:@“sendereRTCUserId”];
[dictParam setObject:self.strThreadId forKey:@”threadId”];

[[eRTCChatManager sharedChatInstance]
sendVideoMediaItemWithParam:dictParam andFileData:data];

Swift

let dictParam =
["appUserId":"appUserId","threadId":"threadId"]
eRTCChatManager.sharedChatInstance().sendAudioMediaItem(
withParam: dictParam, andFileData: data! as Data)

Send typing status

Objective C

NSMutableDictionary * dictParam = [NSMutableDictionary new];
[dictParam setObject:self.dictUserDetails[@"userId"] forKey:@"userId"];
[dictParam setObject:[[UserModel sharedInstance]
getUserDetailsUsingKey:@"eRTCUserId"] forKey:@"eRTCUserId"];
[dictParam setObject:[NSString stringWithFormat:@"on"]
forKey:@"typingStatusEvent"]; //on/off

[[eRTCChatManager sharedChatInstance] sendTypingStatus:dictParam];

Swift

let dictParam = ["userId":"userId","eRTCUserId":"eRTCUserId",”typingStatusEvent”:”on”]
eRTCChatManager.sharedChatInstance().sendTypingStatus(dictParam)

Send Read Message status

Receiver Message Handler

Add Observer in controller

Objective C

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMessageNotification:)
name:@”didRecievedMessageNotification”
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveTypingStatusNotification:)
name:@”didRecievedTypingStatusNotification”
Object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMsgStatus:)

name:@’’didRecievedMessageReadStatusNotification”
object:nil];

Swift

NotificationCenter.default.addObserver(self, selector:
#selector(self.didRecievedMessageNotification(_:)), name:
DidRecievedMessageNotification, object: nil)

NotificationCenter.default.addObserver(self, selector:
#selector(self.didRecievedTypingStatusNotification(_:)),
name: DidRecievedTypingStatusNotification, object: nil)

NotificationCenter.default.addObserver(self, selector:
#selector(self.’’didRecievedMessageReadStatusNotification(_:)),
name: DidRecievedMessageReadStatusNotification, object: nil)

How to Add the eRTC Client SDK to your IOS project?

Add the eRTC SDK development pods to your Podfile.

use_frameworks!
      pod “eRCTSDK”

Run pod install to get the latest version of the code.

Run pod update to get the latest version of the code (optional for pod update).

How to initialise eRTC SDK in App ?

Open the App Delegate add the following code to initialise the chat

Objective C

AppDelegate.m -> application: didFinishLaunchingWithOptions:

     #import <eRTC/eRTCSDK.h>

     [eRTCSDK initialise];

Swift

AppDelegate.m -> application: didFinishLaunchingWithOptions:

import <eRTC/eRTC.h>

Add the following code to the start of your
didFinishLaunchingWithOptions function:
eRTCSDK.initialize()

How to authenticate NameSpace with eRTC SDK ?

Objective C

[eRTCSDK
validateNameSpaceWithWorkSpaceName:@“www..sampleApp.com” withSuccess:^(BOOL isValid,NSString *errMsg) {
   NSLog(@“Response—> %@", isValid);


} andFailure:^(NSError *error) {
   NSLog(@"error”—> %@", [error localizedDescription]);

}];

How to setup Firebase ?

Go to the Firebase website and sign up

Go to the Firebase console and make a new project

Click Add project

Choose a name and a location

Click Settings (the gear icon). On the General tab, click Add Firebase to your iOS app

Enter your bundle ID

Download the GoogleServices file and add it to the root of your Xcode project

How to setup Push Notifications ?

Click here for Configuring APNs with FCM

Resources

The Chat SDK is broken down into the following major parts:

CoreData: This includes definitions and common services and functions.
Core: This stores all the user data , thread and message data.
ChatManager: This component handles communication with the network.
SocketManager: This component handles real time communication via MQTT.