iOS SDK
IOS SDK

Overview

eRTC SDK is a fully featured enterprise solution for instant messaging framework for iOS.
It is scalable, 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 “eRTCSDK”
  • 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 and add the following code to initialize the chat.

Objective C

AppDelegate.m -> application: didFinishLaunchingWithOptions:

#import <eRTC/eRTCSDK.h>

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

[eRTCSDK alloc]initWithApiKey:API_KEY];

Swift

AppDelegate.m -> application: didFinishLaunchingWithOptions:

import <eRTC/eRTC.h>

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

eRTCSDK.initWithApiKey()

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": @email”,
@"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": @"email",
"appUserId":USER_EMAIL,"password": USER_PASSWORD];


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

Forgot Password

Objective C

NSDictionary *dictParam = @{@"loginType": @”email”,
@"appUserId": USER_EMAIL};

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


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

Swift

let dictParam = ["loginType": "email", "appUserId": USER_EMAIL];


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

Change Password

Objective C

NSDictionary *dictParam = @{@"loginType": @”email”, @"appUserId":
USER_EMAIL, @"currentPassword": CURRENT_PASSWORD,
@"newPassword": NEW_PASSWORD};

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


   } else {

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

Swift

let dictParam = ["loginType": "email","appUserId":
"USER_EMAIL","currentPassword":CURRENT_PASSWORD,"newPassword":
NEW_PASSWORD]

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 a thread with the recipient.
For example when you select any user you need to call thread api.

[dictParam setObject:RECIPIENT_EMAIL_ID forKey:@”recipientAppUserId”];
[dictParam setObject:LOGGED_IN_USER_eRTC_USER_ID
forKey:@”sendereRTCUserId”];

    [[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": RECIPIENT_EMAIL_ID,"sendereRTCUserId":
LOGGED_IN_USER_eRTC_USER_ID]
      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);

} andFailure:^(NSError * _Nonnull error) { 
    NSLog(@"error--> %@",error);
}];

Swift

let dictParam = ["sendereRTCUserId": "","threadId":"","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:@”” 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:@”” forKey:@“sendereRTCUserId”];
  [dictParam setObject:@”” 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:@”” forKey:@“sendereRTCUserId”];
  [dictParam setObject:@”” forKey:@”threadId”];

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

Swift

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

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

Send Typing Status:

Objective C

NSMutableDictionary * dictParam = [NSMutableDictionary new];
[dictParam setObject:@”” forKey:@"userId"];
[dictParam setObject:@”” forKey:@"eRTCUserId"];
[dictParam setObject:[NSString stringWithFormat:@"on"]
forKey:@"typingStatusEvent"]; //on/off

[[eRTCChatManager sharedChatInstance] sendTypingStatus:dictParam];

Swift

let dictParam = ["userId":"","eRTCUserId":"",”typingStatusEvent”:”on”]

eRTCChatManager.sharedChatInstance().sendTypingStatus(dictParam)

Send Read Message Status:

Objective C

NSDictionary * dictMessage = [notification userInfo];
[[eRTCChatManager sharedChatInstance] updateMessageWithReadStatus:dictMessage]

Receiver Message Handler:

Add Observer in controller

Objective C

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

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

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

name:@’’didReceivedMessageReadStatusNotification”
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)

User Block & Unblock

Objective C

NSMutableDictionary*dict = [[NSMutableDictionary alloc]init];
[dict setValue:USER_EMAIL forKey:App_User_ID];
[dict setValue:BLOCK/UNBLOCK forKey:@"blockUnblock"]; // block / unblock

[[eRTCAppUsers sharedInstance] ContactblockUnblock:dict andCompletion:
^(id _Nonnull json, NSString * _Nonnull errMsg) {

NSLog(@"json%@",json);

} andFailure:^(NSError * _Nonnull error) {
    NSLog(@"error%@",error);

}] ;

Swift

var dict: [AnyHashable : Any] = [:]
dict[@”userid”] = USER_EMAIL
dict["blockUnblock"] = BLOCK/UNBLOCK // block / unblock

eRTCAppUsers.sharedInstance().contactblockUnblock(dict, andCompletion: { json, errMsg in

    print("json\(json)")

}, andFailure: { error in

    print("error\(error)")
})

Get User Block & Unblock List

Objective C

[[eRTCAppUsers sharedInstance]getContactblockUnblock:^(id _Nonnull json, NSString
* _Nonnull errMsg) {
   NSLog(@"json%@",json);
} andFailure:^(NSError * _Nonnull error) {
   NSLog(@"error%@",error);

}];

Swift

eRTCAppUsers.sharedInstance().getContactblockUnblock({
json, errMsg in
   print("json\(json)")
}, andFailure: { error in
   print("error\(error)")
})

Share Location:

NSMutableDictionary*dictlocation = [[NSMutableDictionary alloc]init];
[dictlocation setValue:LATITUDE forKey:@"latitude"];
[dictlocation setValue:LONGITUDE forKey:@"longitude"];
[dictlocation setValue:ADDRESS forKey:@"address"];

NSMutableDictionary*dictParam = [[NSMutableDictionary alloc]init];
[dictParam setValue:THREAD_ID forKey:@”threadId”];

[dictParam setValue:userId forKey:@”sendereRTCUserId”];
[dictParam setValue:@"location" forKey:@”msgType”];
[dictParam setValue:dictlocation forKey:@"location"];


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

      NSLog(@" json %@ %@",json, errMsg);

    } andFailure:^(NSError * _Nonnull error) {

      NSLog(@" error %@",error);

}];

Share Contact:

NSMutableDictionary*dictParam = [[NSMutableDictionary alloc]init];
    [dictParam setValue:THREAD_ID forKey:@”threadId”];
    [dictParam setValue:userId forKey:@”sendereRTCUserId”];
    [dictParam setValue:@"contact" forKey:@”msgType”];
    [dictParam setValue:contact forKey:@"contact"];

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

      } andFailure:^(NSError * _Nonnull error) {

      }];

Get List of All Groups:

[[eRTCChatManager sharedChatInstance]getuserGroups:nil andCompletion:^(id _Nonnull json,
NSString * _Nonnull errMsg) {

      NSLog(@" json %@ %@",json, errMsg);
         }
andFailure:^(NSError * _Nonnull error) {
      NSLog(@" error %@",error);

    }];

Create Private Group

Objective C

NSMutableDictionary*dictParam = [[NSMutableDictionary alloc]init];

[dictParam setValue: ARRAY_OF_SELECTED_USER_EMAIL forKey:@”participants”];
[dictParam setValue:GROUP_NAME forKey:@”name”];
[dictParam setValue:@"private" forKey:@”groupType”];

    If group image is selected then pass image as NSdata form.
    If group image not selected then pass nil

[[eRTCChatManager sharedChatInstance] CreatePrivateGroup:dictParam
withGroupImage:groupImageData andCompletion:^(id _Nonnull json, NSString * _Nonnull errMsg) {
        NSLog(@"json %@ %@",json, errMsg);

      } andFailure:^(NSError * _Nonnull error) {

}];

Swift

var dict: [AnyHashable : Any] = [:]
let strAppUserID = dictUserDetails[@”userid”]
dict[@”userid”] = strAppUserID
dict[@”GroupName”] = ""
dict[@”Groupdescription”] = "thisGroup"
eRTCChatManager.sharedChatInstance().createPrivateGroup(dict,
andCompletion: { json, errMsg in
   print("json\(json)")
}, andFailure: { error in
   print("error\(error)")
})

Add Participants in Group

Objective C

NSMutableDictionary*dictParam = [[NSMutableDictionary alloc]init];
  [dictParam setValue:GROUP_ID forKey:@”groupId”];
   [dictParam setValue: ARRAY_OF_SELECTED_USER_EMAIL forKey:@”participants”];


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

      NSLog(@"json %@ %@",json, errMsg);

    } andFailure:^(NSError * _Nonnull error) {

    }]

Swift

var dict: [AnyHashable : Any] = [:]
let strAppUserID = dictUserDetails[@”userid”]
dict[@”userid”] = strAppUserID
dict[@”GroupName”] = ""
dict[@”Groupdescription”] = "thisGroup"
eRTCChatManager.sharedChatInstance().groupAddParticipants(dict,
andCompletion: { json, errMsg in
   print("json\(json)")
}, andFailure: { error in
   print("error\(error)")
})

Remove Participants From Group

Objective C

NSMutableDictionary*dict = [[NSMutableDictionary alloc]init];

[dict setValue:PARTICIPANT_eRTC_UserID forKey:@”eRTCUserId”];
[dict setValue:@[ARRAY_OF_PARTICIPANTS_EMAIL]] forKey:@”participants”];
[dict setValue:GROUP_ID forKey:@”groupId”];

[[eRTCChatManager sharedChatInstance]groupRemoveParticipants:dict andCompletion:^(id _Nonnull
json, NSString * _Nonnull
      errMsg)
      {
         NSLog(@"groupRemoveParticipants json %@ %@",json, errMsg);

      }andFailure:^(NSError * _Nonnull error) {
         NSLog(@" removeParticipants error %@",error);
      }];

Swift

var dict: [AnyHashable : Any] = [:]
let strAppUserID = dictUserDetails[@”userid”]
dict[@”userid”] = strAppUserID
dict[@”GroupName”] = ""
dict[@”Groupdescription”] = "thisGroup"
eRTCChatManager.sharedChatInstance().groupRemoveParticipants(dict,
andCompletion: { json, errMsg in
   print("json\(json)")
}, andFailure: { error in
   print("error\(error)")
})

Make OR Dismiss Admin:

Objective C

NSMutableDictionary*dict = [[NSMutableDictionary alloc]init];

    [dict setValue:PARTICIPANT_eRTC_USER_ID forKey:@"eRTCUserId"];
    [dict setValue:GROUP_ID forKey:@”groupId”];
    [dict setValue:PARTICIPANTS_EMAIL forKey:@"targetAppUserId"];
    [dict setValue:MAKE/DISMISS forKey:@”action”]; // make/dismiss


[[eRTCChatManager sharedChatInstance]groupmakeDismissAdmin:dict andCompletion:^(id _Nonnull
json, NSString * _Nonnull errMsg) {
      NSLog(@" json %@ %@",json, errMsg);

    }andFailure:^(NSError * _Nonnull error) {


    }];

Get Group ByGroup-ID

Objective C

NSMutableDictionary*dict = [[NSMutableDictionary alloc]init];
[dict setValue:GROUP_ID forKey:@”groupId”];

[[eRTCChatManager sharedChatInstance]getGroupByGroupId:dict andCompletion:^(id _Nonnull
json, NSString * _Nonnull errMsg) {
        NSLog(@" json %@ %@",json, errMsg);

      }andFailure:^(NSError * _Nonnull error) {
        NSLog(@" error %@",error);

      }];

Swift

var dict: [AnyHashable : Any] = [:]
let strAppUserID = dictUserDetails[App_User_ID]
dict[App_User_ID] = strAppUserID
dict[Group_Name] = ""
dict[Group_description] = "thisGroup"
eRTCChatManager.sharedChatInstance().getGroupByGroupId(dict,
andCompletion: { json, errMsg in
   print("json\(json)")
}, andFailure: { error in
   print("error\(error)")
})

Update Group:

Objective C

NSMutableDictionary*dict = [[NSMutableDictionary alloc]init];
[dict setValue:GROUP_ID forKey:@”groupId”];

[[eRTCChatManager sharedChatInstance]getGroupByGroupId:dict andCompletion:^(id _Nonnull json,
NSString * _Nonnull errMsg) {
    NSLog(@" json %@ %@",json, errMsg);

}andFailure:^(NSError * _Nonnull error) {
    NSLog(@" error %@",error);

}];

How to add eRTC SDK to your iOS project?

  • Add the eRTC SDK development pods to your Podfile.
    use_frameworks!
           pod “eRTCSDK”
  • 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 Initialize 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>

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

[eRTCSDK alloc]initWithApiKey:API_KEY];

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?

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


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

}];

How to set up 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 set up Push Notifications?

Click here for Configuring APNs with FCM

Resources

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

  • Core: This includes definitions and common services and functions.
  • CoreData: 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.