Chat APIs and In-app Messaging SDKs for Developers

Applozic provides Chat APIs and In-app Messaging SDKs for Android, iOS and Web apps to power cross-device, multi-platform rich messaging.
Find comprehensive guides and platform-specific Chat API documentation to get started with In-app Messaging.

Get Started    

iOS

User authentication guide

Pre-built customizable chat UI - Authentication

Once you have all the libraries added. The next step is to setup user registration and authentication for chat.

Why do you need this?
Authentication helps you do two things

  1. It helps you to identify users i.e. differentiate between the users who have access to chat from those who do not have access to chat.
  2. Setup user profiles usually necessary for chat

Where should I put this?
The authentication process allows you to create users or log them into chat whenever necessary. This is usually done along with the login or registration of users within your app i.e. within the login or register buttons in your app.

A sample button's in the image below

Another thing you must understand is, in case of Applozic SDK both Registering a new user and loging in an existing user has the same process and code.

This code is available for both Objective C and Swift, which will be explained later with samples.

The user itself though is identified using a unique Userid and Password that has to be defined by you.

User ID

For a new user of your app to be able to access Applozic chat, it is necessary that the user is registered with Applozic system with a unique USERID.

This userid is then used to not only allow your users to login into chat but also to identify the user within Applozic system, especially useful when you are trying to download the chat history of a particular user.

In the installation step we setup Cocopods to install libraries necessary for Applozic Chat.

The next step in the process is to Register or login your user into the chat.

But before we can do this. There are methods you would require to implement this stage. These methods and the process to import these methods are as follows

Importing Methods for Authentication

The method file that we need here is ALChatManager file, depending on which SDK you use the steps associated with this file also changes.

For ApplozicSwift SDK ::

  1. you would need to download the ALChatManager.swift file and add it to your project

  2. Once done replace "applozic-sample-app" with your App ID. In this case, "applozic-sample-app" is in the ALChatManager.swift file

For Applozic SDK ::
We are compatible with

  1. Objective C
  2. Swift

The process to download ALChatManager for both these languages are described below.

1. Objective C

The process is as follows

Once you have the App ID, replace it in ALChatManager.h file

Have Question Or Suggestion?

You can drop us your query at docs@applozic.com.

2. Swift

If you are using Swift,

  • you would need to download the ALChatManager.swift file and add it to your project

  • Once done replace "applozic-sample-app" with your App ID. In this case, "applozic-sample-app" is in the ALChatManager.swift file

Register/Login the User

Note

Please remember you have to log in once and only after you log out you must log in again. Use below code to check if the user is already logged in.

To check if the user is logged in, use this code:

if (![ALUserDefaultsHandler isLoggedIn]) {
    // Connect user
}
if !ALUserDefaultHandler.isLoggedIn() {
	// Connect user
}

After adding the files into your project, you are ready to create the process to login or register the user to chat.

The Userid itself can be in alphanumeric with the size not exceeding 150 characters and does not allow + * ? : characters in it.

Using ApplozicSwift or Applozic Core SDK

The process is divided into 3 sections i.e.

  • Creating "ALUser" and Passing user details
  • Saving these details
  • Registering or Login in the User:- Don't forget to replace "<APP_ID>" with your App ID from your Applozic account

Recommended Authentication

We recommend using our Access Token based authentication as the password. More details regarding the same can be found here---> Access Token

For ApplozicSwift SDK ::

//Creating "ALUser" and Passing user details
let alUser : ALUser =  ALUser()
alUser.userId = "demoUserId"     // NOTE : +,*,? are not allowed chars in userId.
alUser.email = "github@applozic.com"
alUser.imageLink = ""    							// User's profile image link.
alUser.displayName = "DemoUserName"  	// User's Display Name
alUser.password = "testpassword" //User password
alUser.applicationId = "<APP_ID>"


//Saving these details
ALUserDefaultsHandler.setUserId(alUser.userId)
ALUserDefaultsHandler.setEmailId(alUser.email)
ALUserDefaultsHandler.setDisplayName(alUser.displayName)


//Registering or Login in the User 
let chatManager = ALChatManager(applicationKey: "<APP_ID>")
chatManager.connectUser(alUser, completion: { response, error in
    if error != nil {
        print("Error while logging \(error)")
    } else {
        print("Successfull login")
    }
})

For core Applozic SDK ::

//Creating "ALUser" and Passing user details
// Except UserId all the other parameters are optional

ALUser *alUser = [[ALUser alloc] init];
[alUser setUserId:@"testUser"]; //NOTE : +,*,? are not allowed chars in userId.
[alUser setDisplayName:@"Applozic Test"]; // Display name of user 
[alUser setContactNumber:@""];// formatted contact no
[alUser setImageLink:@"user_profile_image_link"];// User's profile image link.
[alUser setPassowrd:@"testpassword"]; //Password for the user

//Saving the details
[ALUserDefaultsHandler setUserId:alUser.userId];
[ALUserDefaultsHandler setEmailId:alUser.email];
[ALUserDefaultsHandler setDisplayName:alUser.displayName];


//Registering or Loging in the User
ALChatManager * chatManager = [[ALChatManager alloc] initWithApplicationKey:@"<APP_ID>"]; // Replace this with your App ID
[chatManager connectUserWithCompletion:alUser withHandler:^(ALRegistrationResponse *rResponse, NSError *error) {
        
      if (!error)
      {
      	//Applozic registration successful
      }
      else
      {
          NSLog(@"Error in Applozic registration : %@",error.description);
      }
}];
//Creating "ALUser" and Passing user details
let alUser : ALUser =  ALUser()
alUser.userId = "demoUserId"     // NOTE : +,*,? are not allowed chars in userId.
alUser.email = "github@applozic.com"
alUser.imageLink = ""    							// User's profile image link.
alUser.displayName = "DemoUserName"  	// User's Display Name
alUser.password = "testpassword" //User password


//Saving these details
ALUserDefaultsHandler.setUserId(alUser.userId)
ALUserDefaultsHandler.setEmailId(alUser.email)
ALUserDefaultsHandler.setDisplayName(alUser.displayName)


//Registering or Login in the User 
 let chatManager = ALChatManager(applicationKey: "applozic-sample-app")
         chatManager.connectUserWithCompletion(alUser) { (response, error) in
            if (error == nil)
            {
                print("Error");
            }else{
                print("Login success")
            }
     }

Adding additional fields in User

Sometimes you might need to add custom parameters or fields to your User data which can be used within your application to personalize chat.

If you are looking at such a requirement, the following code can help you add additional fields to the METADATA of your user. These values can be retrieved using the Unique Userid that you would have set in previous steps.

In the following sample code below
Designation
City
Country
are the additional fields/information that you might want to add to a chat user.

 NSMutableDictionary *userMetaData = [[NSMutableDictionary alloc] init];
 [userMetaData setValue:@"Software engineer" forKey:@"designation"];
 [userMetaData setValue:@"Bengaluru" forKey:@"city"];
 [userMetaData setValue:@"India" forKey:@"country"];
 [user setMetadata:userMetaData];
var userMetaData = [AnyHashable: Any]()
 userMetaData["designation"] = "Software engineer"
 userMetaData["city"] = "Bengaluru"
 userMetaData["country"] = "India"
 user.metadata = userMetaData as! NSMutableDictionary

TOKEN - Validation

With data security being one of our biggest priorities, we recommend that you use an access token based methodology to validate your Users.

The general process flow is shown below

To begin with you would need to create an Access Token URL at your server side, please follow the instructions here---> Access Token URL

Once done please follow the process below for Client side validation

  1. In your ALChatManager.m file, please add the following method to ALDefaultChatViewSettings
[ALUserDefaultsHandler setUserAuthenticationTypeId:(short)CLIENT];
ALUserDefaultsHandler.setUserAuthenticationTypeId(CLIENT)
  1. Once you finish the setup, you would have to generate a unique Access Token for each user that you register with Applozic.

This Access Token would replace your Password Parameter in your ALUser object under Register/Login setup mentioned above.

[user setPassword:<YOUR ACCESS TOKEN>]; //set password value
user.setPassword(<YOUR ACCESS TOKEN>)

Password update

You can use the below method to update login user password, you need to pass the old password and new password to update

  ALUserService *aLUserService = [[ALUserService alloc] init];
    [aLUserService updatePassword:@"oldPassword" withNewPassword:@"newPassword" withCompletion:^(ALAPIResponse *alAPIResponse, NSError *theError) {
        
        if(!theError){
            NSLog("Update password successfully");
        }
    }];
 let userService = ALUserService()
 userService.updatePassword("oldPassword", withNewPassword: "newPassword") { (alApiResponse, error) in
         if(error == nil){
                print("Password updated successfully")
          }
  }

Update User Details

Use this API to update the user details after the user has been registered.

ALUserService *userService = [ALUserService new];
[userService updateUserDisplayName:@"" andUserImage:imageLinkFromServer userStatus:@"" withCompletion:^(id theJson, NSError *error) {
  
}];
let userService = ALUserService()
userService.updateUserDisplayName("", andUserImage: "<Image url>", userStatus: nil) { (response, error) in
  if error == nil {
      // success
  }
}

Get logged In userId of Applozic user

Use the below setting to get the current login userId in Applozic

[ALUserDefaultsHandler getUserId];
ALUserDefaultsHandler.getUserId()

Build your UI from scratch - Authentication

Building a messaging application with Applozic is very simple. We provide APIs which you can use to build your own UI from scratch

Setup Application

Let's start with the Installation part.

First, Initialise the SDK with the App ID you got from the Applozic Dashboard after sign up . Then next, set up the App ID in the place of <APP_ID> put your App ID.

Custom UI Sample App

You can check out this Custom UI sample app which can be used as a reference. Also, you can clone it and try locally.

Initialise an instance of ApplozicClient to use throughout your app. You can create this in either your app delegate file or a ViewController class, for example:

There are two ways to Initialise

Create ApplozicClient variable and access it.

#import <Applozic/Applozic.h>

@property (strong, nonatomic) ApplozicClient *applozicClient;
import Applozic
  
 var  applozicClient = ApplozicClient()

1) One way is without real-time updates delegate callbacks

self.applozicClient = [[ApplozicClient alloc ]initWithApplicationKey:@"<APP_ID>"]; //Pass App ID here 
  applozicClient = ApplozicClient(applicationKey: "applozic-sample-app") as ApplozicClient //Pass App Id here 
       

2) Another way is with real-time update delegate callbacks

self.applozicClient = [[ApplozicClient alloc]initWithApplicationKey:@"<APP_ID>" withDelegate:self]; //Pass your App ID
applozicClient = ApplozicClient(applicationKey: "applozic-sample-app", with: self) as ApplozicClient //Pass your App ID
       

How to get applicationKey?

You need to sign up at https://www.applozic.com. Under the Install section, App ID will be present.

Register/Login the User From Client

In the case of Applozic SDK, both Registering a new user and logging in an existing user has the same process and code.

This code is available for both Objective C and Swift, which are explained below with samples.

The user itself though is identified using a unique Userid and Password that has to be defined by you.

UseId
For a new user of your app to be able to access Applozic chat, it is necessary that the user is registered with Applozic system with a unique USERID.

This userId is then used to not only allow your users to login into chat but also to identify the user within Applozic system, especially useful when you are trying to download the chat history of a particular user.

The UserId itself can be in alphanumeric with the size not exceeding 150 characters and does not allow +*?/: characters in it.

  ALUser *user = [[ALUser alloc] init];
  user.userId = @"userId";
  user.password = @"password";
  user.displayName = @"displayName";
  user.imageLink = @"imageUrlLink";
  user.authenticationTypeId = APPLOZIC;
    
  [self.applozicClient loginUser:user withCompletion:^(ALRegistrationResponse *response, NSError *error) {
        
        if(!error){
            NSLog(@"Login success");
        }
    }];
 let user = ALUser()
 user.userId = "userid" //pass the login userId
 user.password = "password" //pass the password
 user.imageLink = ""  // User's profile image link.
 user.displayName = "DemoUserName" // User's Display Name   
 ALUserDefaultsHandler.setUserAuthenticationTypeId(Int16(APPLOZIC.rawValue))
       
  applozicClient.loginUser(user, withCompletion: { response, error in
           if error == nil {
                print("Login success")
            }
   })

What's Next

Conversation

iOS


User authentication guide

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.