fm-applozic-chat
v1.0.0
Published
Downloads
3
Readme
Applozic NativeScript Chat Plugin
Installation
tns plugin add nativescript-applozic-chat
Goto src folder and run
npm run demo.ios
Usage
Login/Register User
var alUser = {
'userId' : userId, //Replace it with the userId of the logged in user
'password' : password, //Put password here
'authenticationTypeId' : 1,
'applicationId' : 'applozic-sample-app', //replace "applozic-sample-app" with Application Key from Applozic Dashboard
'deviceApnsType' : 0 //Set 0 for Development and 1 for Distribution (Release)
};
applozicChat.login(alUser, function(response) {
applozicChat.launchChat(); //launch chat
}, function(error) {
console.log("onLoginFailure: " + error);
});
Launch Chat
Main Chat screen
applozicChat.launchChat();
Launch Chat with a specific User
applozicChat.launchChatWithUserId(userId);
Launch Chat with specific Group
applozicChat.launchChatWithGroupId(groupId, function(response){
console.log("Success : " + response);
}, function(response){
console.log("Error : " + response);
});
Logout
applozicChat.logout(function(response) {
console.log("logout success: " + response);
}, function(error) {
console.log("logout error: "+ error);
});
Push Notification Setup instruction
Uploading the push notification certificate and GCM/FCM server key in applozic dashboard
a) For IOS upload your APNS push notification certificate to Applozic Dashboard page under 'Edit Application' section in order to enable real-time notification.
Go to Applozic Dashboard ->Action -> Edit -> Push Notification -> Upload APNS Certificate for Development and Distribution environment.
b) For Android go to Applozic Dashboard and update the GCM/FCM server key under Action -> Edit -> Push Notification -> Android -> GCM/FCM Server Key.
Android
Prerequisites:
- Download these files https://github.com/reytum/Applozic-Push-Notification-FIles
- Register you application in firebase console and download the
google-services.json
file. - Get the FCM server key from firebase console.(There is a sender ID and a server key, make sure you get the server key).
- Go to applozic dashboard https://dashboard.applozic.com/, and put the GCM/FCM server key under Action -> Edit -> Push Notification -> Android -> GCM/FCM Server Key.
Steps to follow:
Copy the
pushnotification
folder from the above downloaded files and paste it in path<your project>/platforms/android/src/main/java/com/tns/
Add these lines in file
<your project>/platforms/android/src/main/AndroidManifest.xml
inside<application>
tag<service android:name="com.tns.pushnotification.FcmListenerService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <service android:name="com.tns.pushnotification.FcmInstanceIDListenerService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service>
Add the same lines from step 2 in
<your project>/app/App_Resources/Android/AndroidManifest.xml
file inside<application>
tagPaste the
google-services.json
file in<your project>/platforms/android/
folderOpen
<your project>/platforms/android/build.gradle
: add this inside dependency mentioned in top of the file (belowclasspath "com.android.tools.build:gradle:2.2.3"
) :classpath "com.google.gms:google-services:3.1.1"
add this belowapply plugin: "com.android.application"
:apply plugin: "com.google.gms.google-services"
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); });
Note : Everytime you remove and add android platform you need to follow steps 1,2,4 and 5.
Ios
Download delegate.ts file from this delegate.ts link and paste it under
your project folder-->app-->delegate.ts
Download app.ts file from the 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 link
NOTE : Above push notification setup for android and ios is in the case if your not using native script push plugin in your project