IOS SDK

In-App Chat iOS SDK

Overview

eRTC SDK is a fully featured enterprise solution for instant messaging framework for iOS. eRTC SDK is fully featured, 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 “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 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 initialise];

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!)
}

Log in 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(wit
hParam: 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 typing status

Objective C

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

Receive message handler

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)

User block and 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

let strAppUserID = dictUserDetails[@””]
//NSString*username = self.dictUserDetails[@”username”];

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 and 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().createPrivateGroup(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-by-group 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

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 “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 initialize eRTC SDK in app?

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.