Chat APIs and In-app Messaging SDKs for Developers, by Developers

Applozic powers multi-platform Chat APIs and in-app Messaging SDKs for Android, iOS and the Web that will enable you to build advanced in-app chat solutions your users will love.

Integrate chat in your application with completely customizable UI kits, powerful messaging APIs and SDKs, developed with exceptional security measures in mind.

Guides    API Explorer

NativeScript

NativeScript push notification setup

Android

1) If you haven't already added firebase to your project, Register your application in firebase console and download the google-services.json file keep it needed in next steps.

2) For getting FCM server key from firebase click Settings icon --> Project settings

3) Once you clicked Project settings select Cloud Messaging tab under Settings. Under Project Credentials, copy your Server Key which is highlighted blue in the below following image

4) Update FCM server key in applozic dashboard

Go to Applozic Dashboard Push Notification section and put your FCM server key there.

Push Notifications setup

  1. Download this FcmListenerService.java file from the link https://github.com/AppLozic/Applozic-Android-SDK/tree/master/app/src/main/java/com/applozic/mobicomkit/sample/pushnotification

  2. Copy the FcmListenerService.java from the above downloaded file and paste it in path <YOUR_PROJECT>/platforms/android/src/main/java/com/tns/

  3. Change package name by opening the file FcmListenerService.java at line number 1
    package com.applozic.mobicomkit.sample.pushnotification; to new package where the file exist

<service
      android:name=".FcmListenerService"
      android:exported="true"
      android:stopWithTask="false">
          <intent-filter>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
 </service>

NOTE: If you're using the Nativescript firebase plugin then add the below entry in your <YOUR_PROJECT>/app/App_Resources/Android/AndroidManifest.xml file and change else ignore this below change.

<service
            android:name="org.nativescript.plugins.firebase.MyFirebaseMessagingService"
            tools:node="remove" />

NOTE: If you're using the Nativescript firebase plugin else ignore this below change.

Open the FcmListenerService file and extends it with MyFirebaseMessagingService instead of FirebaseMessagingService and add the import org.nativescript.plugins.firebase.MyFirebaseMessagingService;

  1. Add the same lines from step 2 in <YOUR_PROJECT>/app/App_Resources/Android/AndroidManifest.xml file inside <application> tag

  2. Paste the google-services.json file in <YOUR_PROJECT>/platforms/android/ folder

  3. Open <your project>/platforms/android/build.gradle : add this inside dependency mentioned in top of the file (below classpath "com.android.tools.build:gradle:2.2.3" ) : classpath "com.google.gms:google-services:3.1.1" add this below apply plugin: "com.android.application" : apply plugin: "com.google.gms.google-services"

  4. Call PushNotificationTask in onSuccess of applozic login as below:

applozicChat.registerForPushNotification(function(response){
   console.log("push success : " + response);
 }, function(response){
   console.log("push failed : " + response);
 });

IOS

Setting up APNs Certificates

Applozic sends the payload to Apple servers which then sends the push notification to your user's device.

Creating APNs certificates

A sample is shown below shows what your certificate should look like once you create it
For Apple to send these notifications, you would have to create APNs certificate in your Apple developer account.
Visit

  1. https://developer.apple.com/account/ios/certificate/development, to create development APNs certificate

A sample is shown below shows what your certificate should look like once you create it

  1. https://developer.apple.com/account/ios/certificate/distribution, to create a distribution certificate

a sample is shown below

Upload APNs Certificates

Upload your push notification certificates (mentioned above) to Applozic Dashboard page under 'Edit Application' section in order to enable real-time notification.

Go to Applozic console -> Click on Settings -> Push Notification ->

Upload APNS Certificate for Development and Distribution environment.

Updating Capabilities

Post setting up APNs, the next step is to enable push notifications within your project. To do that
Click on your project ----> Click on Capabilities and enable

  1. Push Notifications
  2. Background Modes - Fetch and Remote notification

Following screenshots would be of help.

Push Notifications setup

There are two ways for push notification setup either one way you can choose

A) Without using native script push plugin for push notification

NativeScript 7

If your project is using NS 7 then go with this step else ignore

Add the below complete code in your app.ts or main.ts file

import { Application, isIOS } from "@nativescript/core";
import { ApplozicChat } from "nativescript-applozic-chat";
declare var ALRegisterUserClientService: any;
declare var ALPushNotificationService: any;

/// Applozic start
/// NOTE: add the above imports as well in your app.ts file and also make sure that  this below code need be above the Application.run else wont work.

if (Application.ios) {
    @NativeClass
    class CustomAppDelegate extends UIResponder
    implements
    UIApplicationDelegate,
    UNUserNotificationCenterDelegate {
      public static ObjCProtocols = [
        UIApplicationDelegate,
        UNUserNotificationCenterDelegate
      ];

      private keyWindow: UIWindow;

      get window(): UIWindow {
        return this.keyWindow;
      }
      set window(v: UIWindow) {
        this.keyWindow = v;
      }

      applicationDidFinishLaunchingWithOptions(
        application: UIApplication,
        launchOptions
      ): boolean {
        console.log("applicationWillFinishLaunchingWithOptions: ", this);
        this.registerPushNotification();

        application.applicationIconBadgeNumber = 0;
        application.cancelAllLocalNotifications();
        let alPushNotificationService = ALPushNotificationService.alloc().init();
        alPushNotificationService.checkForLaunchNotification(launchOptions);
        return true;
      }

      applicationDidBecomeActive(application: UIApplication): void {
        console.log("applicationDidBecomeActive:  " + application);
        console.log("is registered", application.registeredForRemoteNotifications);
        this.keyWindow = application.keyWindow;
      }

      applicationDidRegisterForRemoteNotificationsWithDeviceToken(
        application: UIApplication,
        deviceToken: NSData
      ) {
        let token = deviceToken.debugDescription.replace(/[< >]/g, "");
        console.log("registered for pushed token ", token);
        var alRegisterUserClientService = ALRegisterUserClientService.alloc().init();
        alRegisterUserClientService.updateApnDeviceTokenWithCompletionWithCompletion(token, function(response, error) {
          //Todo: add check for error and call errorCallback in case of error
          console.log("registered for pushed success");

        });
      }

      applicationDidFailToRegisterForRemoteNotificationsWithError(
        application: UIApplication,
        error: NSError
      ) {
        console.error("failed to register push ", error);
      }

      applicationDidReceiveRemoteNotification(
        application: UIApplication,
        userInfo: NSDictionary<any, any>
      ) {
        console.log(
          "applicationDidReceiveRemoteNotification:" + JSON.stringify(userInfo)
        );
        let alPushNotificationService = ALPushNotificationService.alloc().init();
        alPushNotificationService.notificationArrivedToApplicationWithDictionary(
          application,
          userInfo
        );
      }

      applicationDidReceiveRemoteNotificationFetchCompletionHandler(
        application: UIApplication,
        userInfo: NSDictionary<any, any>,
        completionHandler: any
      ) {
        console.log(
          "applicationDidReceiveRemoteNotificationFetchCompletionHandler:" +
          JSON.stringify(userInfo)
        );
        let alPushNotificationService = ALPushNotificationService.alloc().init();
        if(alPushNotificationService.isApplozicNotification(userInfo)) {
          alPushNotificationService.notificationArrivedToApplicationWithDictionary(
            application,
            userInfo
          );
          completionHandler(UIBackgroundFetchResult.NewData);
          return;
        }
        completionHandler(UIBackgroundFetchResult.NewData);
      }

      applicationWillEnterForeground(application: UIApplication) {
        console.log("APP_ENTER_IN_FOREGROUND");
        application.applicationIconBadgeNumber = 0;
      }

      userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler(
        center: UNUserNotificationCenter,
        response: UNNotificationResponse,
        completionHandler: () => void
      ) {
        console.log("DID_RECEIVE_NOTIFICATION_RESPONSE");
        let application = UIApplication.sharedApplication;
        let content = response.notification.request.content;
        let alPushNotificationService = ALPushNotificationService.alloc().init();
        if(alPushNotificationService.isApplozicNotification(content.userInfo)) {
          alPushNotificationService.notificationArrivedToApplicationWithDictionary(
            application,
            content.userInfo
          );
          completionHandler();
          return;
        }
        completionHandler();
      }

      userNotificationCenterWillPresentNotificationWithCompletionHandler(
        center: UNUserNotificationCenter,
        notification: UNNotification,
        completionHandler: (p1: UNNotificationPresentationOptions) => void
      ) {
        console.log("WILL_PRESENT_NOTIFICATION");
        let application = UIApplication.sharedApplication;
        let content = notification.request.content;
        let alPushNotificationService = ALPushNotificationService.alloc().init();
        if (alPushNotificationService.isApplozicNotification(content.userInfo)) {
          alPushNotificationService.notificationArrivedToApplicationWithDictionary(
            application,
            content.userInfo
        );
         completionHandler(0);
         return;
       }
      }

      registerPushNotification(){
        const invokeOnRunLoop = (() => {
          const runloop = CFRunLoopGetMain();
          return func => {
            CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, func);
            CFRunLoopWakeUp(runloop);
          };
        })();
         var application = UIApplication.sharedApplication;
          const authorizationOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge;
          var curNotCenter = UNUserNotificationCenter.currentNotificationCenter();
          curNotCenter.requestAuthorizationWithOptionsCompletionHandler(authorizationOptions, (granted, error) => {
            if (!error) {
            if (application !== null) {
              invokeOnRunLoop(() => {
                console.log("invokeOnRunLoop: ");
                application.registerForRemoteNotifications();
              });
            }
          } else {
            console.log("Error requesting push notification auth: " + error);
          }
        });
    }

  }
   Application.ios.delegate = CustomAppDelegate;
}

🚧

Make sure to add @NativeClass configuration for (typescript based projects)

Check out this link and add the configuration related to @NativeClass() decorator for typescript based project only.
https://nativescript.org/blog/nativescript-7-announcement/

NativeScript 6

If your project is using the NativeScript 6 then go with these steps

  1. Download delegate.ts file from this delegate.ts link and paste it under your project app-->delegate.ts

  2. Download app.ts file from this app.ts link and replace the app.ts file in your project if you have any changes then you can merge only required changes from the app.ts file

📘

NOTE : If you are using the step A then there should not be any native script push plugin on your project else it will clash with native script push plugin and notification will not work.

B) With using native script push plugin

  1. You need to do the native script push plugin setup from this
    GitHub link

https://github.com/NativeScript/push-plugin

once you are done with adding the native script push plugin and setup

a) Add this import statement at top to your .ts file where you want to access the apploizc plugin functions

var nativescript_applozic_chat = require("nativescript-applozic-chat");

b) Creating an object for accessing applozic plugin functions

var applozicChat = new nativescript_applozic_chat.ApplozicChat();

c) For handling the native script push notification callbacks

  1. For IOS: In notification, callback add the proccessNotification method
notificationCallbackIOS: function (data) {
     applozicChat.proccessNotification(data);// Applozic plugin code 

    }

d) Register the token in pushPlugin.register method function :

pushPlugin.register(iosSettings, function (data) {

         applozicChat.refreshToken(data); //Applozic plugin code 

    // Register the interactive settings
      if(iosSettings.interactiveSettings) {
        pushPlugin.registerUserNotificationSettings(function() {
         // alert('Successfully registered for interactive push.');
        }, function(err) {
         // alert('Error registering for interactive push: ' + JSON.stringify(err));
        });
      }
  }, function() { });

2) Add this in your app.ts file which will be inside your project -->app-->app.ts file

import { ApplozicChat } from 'nativescript-applozic-chat';

declare var ALPushNotificationService: any;

application.on(application.launchEvent, function (args: application.ApplicationEventData) {

     var applozicChat = new ApplozicChat();

    if (args.android) {
        // For Android applications, args.android is an android.content.Intent class.
    } else if (args.ios !== undefined) {
        // For iOS applications, args.ios is NSDictionary (launchOptions).
       let alPushNotificationService = ALPushNotificationService.alloc().init();
         alPushNotificationService.checkForLaunchNotification(args.ios);
    }
});

📘

NOTE : If your already using push plugin in your project then you can go with step B

Updated 5 months ago


NativeScript


NativeScript push notification setup

Suggested Edits are limited on API Reference Pages

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