Official iOS SDK for Chat 💬
Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emerging startups and established companies with the most scalable and powerful chat APIs, enabling application product teams to drive better user engagement, and reduce time-to-market.
Customers and developers from over 50+ countries use us and love us, from online marketplaces and eCommerce to on-demand services, to Education Tech, Health Tech, Gaming, Live-Streaming, and more.
Our feature-rich product includes robust client-side SDKs for iOS, Android, React Native, and Flutter. We also support popular server-side languages, a beautifully customizable UI kit, and flexible platform APIs.
Chat, video, and audio-calling have become the new norm in the post-COVID era, and we're bridging the gap between businesses and customers by delivering those exact solutions.
-
Install the following:
-
Make sure that your project meets these requirements:
- Your project must target iOS 10 or later.
- Set up a physical or simulator iOS device to run your app
-
Sign-Up or Login to get your Applozic's API key/App Id.
Before getting started with installation. We recommend to go through some basic documentation for Applozic iOS Chat & Messaging SDK Documentation 📝
- Open Xcode Create a new project Select App and Click Next
- Set the Product Name as per your preference (we will name it as applozic-first-app) and click Next and Select folder then Create.
The iOS Applozic framework can be installed using CocoaPods or Dynamic Frameworks, as you prefer.
Applozic is available through CocoaPods. To install it
- Open Terminal
- Navigate to the root directory of your Project (the directory where your *.xcodeproj file is)
- Run command
pod init
Again go to your Project's root directory, click on the "Podfile" to open. Copy-paste the following code in the file and Save
source 'https://github.com/CocoaPods/Specs'
use_frameworks! # Required to add
platform :ios, '10.0'
target 'TARGET_NAME' do
pod 'Applozic' # Required to add
end
-
Go to your project directory where Podfile there run
pod install
orpod update
from terminal to refresh the CocoaPods dependencies. -
Open your project newly generated
*.xcworkspace
or existing and build your project.
- Download the Applozic latest Chat frameworks from here
- Uncompress the ZIP files inside Debug or Release Applozic and ApplozicCore framework.
- On your application
targets
General settings tab, in theFrameworks, libraries, and embedded content
, drag and drop each xcframework you want to use from the downloaded folder. - Make sure
Always Embed Swift Standard Libraries
isYES
in the build settings of your project.
App Store requires any app which accesses camera, contacts, gallery, location, a microphone to add the description of why does your app needs to access these features.
In the Info.plist file of your project. Please add the following permissions
<key>NSCameraUsageDescription</key>
<string>Allow Camera</string>
<key>NSContactsUsageDescription</key>
<string>Allow Contacts</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow location sharing!!</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allow MicroPhone</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow Photos</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Allow write access</string>
The method file that we need here is ALChatManager
files.
- Download the
ALChatManager.h
here andALChatManager.m
here - Add the Downloaded ALChatManager.h and ALChatManager.m in your project
- Open
ALChatManager.h
file in your Xcode and Replace "applozic-sample-app" with your App ID from here
// 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 setPassword:@"testpassword"]; //Password for the user
//Saving the details
[ALUserDefaultsHandler setUserId:alUser.userId];
[ALUserDefaultsHandler setEmailId:alUser.email];
[ALUserDefaultsHandler setDisplayName:alUser.displayName];
[ALUserDefaultsHandler setUserAuthenticationTypeId:(short)APPLOZIC];
[ALUserDefaultsHandler setPassword:alUser.password];
// Registering or Loging in the User
ALChatManager * chatManager = [[ALChatManager alloc] init];
[chatManager connectUserWithCompletion:alUser withHandler:^(ALRegistrationResponse *rResponse, NSError *error) {
if (!error) {
// Applozic registration successful
} else {
NSLog(@"Error in Applozic registration : %@",error.description);
}
}];
Applozic sends the payload to Apple servers which then sends the Push notification to your user's device.
For Apple to send these notifications, would have to create an APNs certificate in your Apple developer account.
-
Visit this link, to create Apple Push Notification service SSL (Sandbox) i.e development certificate
-
Visit this link, to create Apple Push Notification service SSL (Sandbox & Production) i.e distribution certificate
Once the certificates are created you can download them and export the p12 files with password for development and distribution certificate either from Keychain Acess from Mac.
Upload your push notification certificates (mentioned above) to the Applozic console by referring to the below-given image.
Go to Applozic console push notification section to upload the APNs development and distribution certificates
Add capabilities to configure app services from Apple, such as push notifications, Background modes
-
On the Xcode project’s Signing & Capabilities tab, Click (+ Capability) to add “Push Notifications”
-
Next Click (+ Capability) to add "Background modes" enable this below four options from Background modes
- "Background fetch"
- "Remote notifications"
Following screenshot would be of help.
Add the below imports in the Appdelegate file
#import <Applozic/Applozic.h>
#import <UserNotifications/UserNotifications.h>
Add the following code in AppDelegate.m class, this function will be called after the app launch to register for push notifications.
// UNUserNotificationCenterDelegate are required for APNs call backs please add this delegate to your AppDelegate file
@interface AppDelegate () <UNUserNotificationCenterDelegate>
@end
// didFinishLaunchingWithOptions method of your app
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// checks wheather app version is updated/changed then makes server call setting VERSION_CODE
[ALRegisterUserClientService isAppUpdated];
// Register APNs and Push kit
[self registerForNotification];
// Register for Applozic notification tap actions and network change notifications
ALAppLocalNotifications *localNotification = [ALAppLocalNotifications appLocalNotificationHandler];
[localNotification dataConnectionNotificationHandler];
ALPushNotificationHandler *pushNotificationHandler = [ALPushNotificationHandler shared];
[pushNotificationHandler dataConnectionNotificationHandler];
// Override point for customization after application launch.
NSLog(@"launchOptions: %@", launchOptions);
if (launchOptions != nil) {
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil) {
NSLog(@"Launched from push notification: %@", dictionary);
ALPushNotificationService *pushNotificationService = [[ALPushNotificationService alloc] init];
BOOL applozicProcessed = [pushNotificationService processPushNotification:dictionary updateUI:[NSNumber numberWithInt:APP_STATE_INACTIVE]];
//IF not a appplozic notification, process it
if (!applozicProcessed) {
//Note: notification for app
}
}
}
return YES;
}
// Register APNs
-(void)registerForNotification
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if(!error)
{
dispatch_async(dispatch_get_main_queue(), ^ {
[[UIApplication sharedApplication] registerForRemoteNotifications]; // required to get the app to do anything at all about push notifications
NSLog(@"Push registration success." );
});
}
else
{
NSLog(@"Push registration FAILED" );
NSLog(@"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog(@"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
}
Add the below code in your Appdelegate file if any of these methods already exist then you can copy-paste the code from the below methods.
// APNs device token sending to applozic
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)
deviceToken {
const unsigned *tokenBytes = [deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSString *apnDeviceToken = hexToken;
NSLog(@"apnDeviceToken: %@", hexToken);
if (![[ALUserDefaultsHandler getApnDeviceToken] isEqualToString:apnDeviceToken]) {
ALRegisterUserClientService *registerUserClientService = [[ALRegisterUserClientService alloc] init];
[registerUserClientService updateApnDeviceTokenWithCompletion
:apnDeviceToken withCompletion:^(ALRegistrationResponse
*rResponse, NSError *error) {
if (error) {
NSLog(@"%@",error);
return;
}
NSLog(@"Registration response%@", rResponse);
}];
}
}
Once your app receives notification, pass it to the Applozic handler for chat notification processing.
// UNUserNotificationCenter delegates for chat
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
ALPushNotificationService *pushNotificationService = [[ALPushNotificationService
alloc] init];
NSDictionary *userInfo = notification.request.content.userInfo;
NSLog(@"APNS willPresentNotification for userInfo: %@", userInfo);
if ([pushNotificationService isApplozicNotification:userInfo]) {
[pushNotificationService notificationArrivedToApplication:[UIApplication sharedApplication] withDictionary:userInfo];
completionHandler(UNNotificationPresentationOptionNone);
return;
}
completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(nonnull UNNotificationResponse* )response withCompletionHandler:(nonnull void (^)(void))completionHandler {
ALPushNotificationService *pushNotificationService = [[ALPushNotificationService
alloc] init];
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSLog(@"APNS didReceiveNotificationResponse for userInfo: %@", userInfo);
if ([pushNotificationService isApplozicNotification:userInfo]) {
[pushNotificationService notificationArrivedToApplication:[UIApplication sharedApplication] withDictionary:userInfo];
completionHandler();
return;
}
completionHandler();
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"RECEIVED_NOTIFICATION_WITH_COMPLETION :: %@", userInfo);
ALPushNotificationService *pushNotificationService = [[ALPushNotificationService alloc] init];
if ([pushNotificationService isApplozicNotification:userInfo]) {
[pushNotificationService notificationArrivedToApplication:application withDictionary:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
return;
}
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[[ALDBHandler sharedInstance] saveContext];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NSLog(@"APP_ENTER_IN_FOREGROUND");
[application setApplicationIconBadgeNumber:0];
}
Implement the following code at the event or Button action designated for showing chat list screen.
ALChatManager * chatManager = [[ALChatManager alloc] init];
[chatManager launchChat:self];
On logout of your app you need to logout the applozic user as well use the below method to logout the user:
ALRegisterUserClientService *registerUserClientService = [[ALRegisterUserClientService alloc] init];
[registerUserClientService logoutWithCompletionHandler:^(ALAPIResponse *response, NSError *error) {
if(!error && [response.status isEqualToString:@"success"]) {
NSLog(@"Logout success");
} else {
NSLog(@"Logout failed with response : %@",response.response);
}
}];
All updates to this library are documented in our releases. For any queries, feel free to reach out us at github@applozic.com
If you are interested in the future direction of this project, please take a look at our open issues and pull requests.
We would ❤️ to hear your feedback.
- One to one and Group Chat
- Image capture
- Photo sharing
- Location sharing
- Push notifications
- In App notifications
- Online presence
- Last seen at
- Unread message count
- Typing indicator
- Message sent
- Read Recipients and Delivery report
- Offline messaging
- User block/unblock
- Multi Device sync
- Application to user messaging
- Customized chat bubble
- UI Customization Toolkit
- Cross Platform Support(iOS,Android&Web)
We provide support over at StackOverflow when you tag using applozic, ask us anything.
-
Applozic is the best android chat sdk for instant messaging, still not convinced?
- Write to us at github@applozic.com
- We will be happy to schedule a demo for you.
- Special plans for startup and open source contributors.
-
Android Chat SDK https://github.com/AppLozic/Applozic-Android-SDK
-
Web Chat Plugin https://github.com/AppLozic/Applozic-Web-Plugin
-
iOS Chat SDK https://github.com/AppLozic/Applozic-iOS-SDK
-
iOS Applozic Swfit SDK https://github.com/AppLozic/ApplozicSwift
-
Sample source code in Objective-C to build messenger and chat app link here
-
Sample Projects https://github.com/AppLozic/Applozic-iOS-Chat-Samples
This code library fully developed and supported by Applozic's team of contributors😎 and licensed under the BSD-3 Clause License.