- 版本:1.0.3
- GitHub: https://github.com/xpalacincreditoh/nativescript-applozic-chat-creditoh
- NPM: https://npmjs.net.cn/package/nativescript-applozic-chat-creditoh
- 下载
- 昨天:0
- 上周:1
- 上个月:5
Applozic 原生 Nativescript 聊天插件
是 [email protected] 的分支
安装
tns plugin add nativescript-applozic-chat-creditoh
进入 src 文件夹并运行
npm run demo.ios
用法
登录/注册用户
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);
});
启动聊天
主聊天屏幕
applozicChat.launchChat();
与特定用户启动聊天
applozicChat.launchChatWithUserId(userId);
与特定群组启动聊天
applozicChat.launchChatWithGroupId(groupId, function(response){
console.log("Success : " + response);
}, function(response){
console.log("Error : " + response);
});
登出
applozicChat.logout(function(response) {
console.log("logout success: " + response);
}, function(error) {
console.log("logout error: "+ error);
});
推送通知设置说明
在 applozic 控制台中上传推送通知证书和 GCM/FCM 服务器密钥
a) 对于 iOS,将您的 APNS 推送通知证书上传到 Applozic 控制台页面中的“编辑应用程序”部分,以启用实时通知。
转到 Applozic 控制台推送通知 推送通知 -> 上传开发环境和分发环境的 APNS 证书。
b) 对于 Android,转到 Applozic 控制台推送通知 并在 推送通知 -> GCM/FCM 密钥 下更新 GCM/FCM 服务器密钥。
Android
先决条件
- 下载这些文件 https://github.com/reytum/Applozic-Push-Notification-FIles
- 在 Firebase 控制台中注册您的应用程序并下载
google-services.json
文件。 - 从 Firebase 控制台中获取 FCM 服务器密钥。(有一个发送者 ID 和一个服务器密钥,请确保您获取的是服务器密钥)。
- 转到 Applozic 控制台推送通知 并在 推送通知 -> GCM/FCM 密钥 下更新 GCM/FCM 服务器密钥。
要遵循的步骤
-
将上述下载文件中的
pushnotification
文件夹复制并粘贴到路径<your project>/platforms/android/src/main/java/com/tns/
-
在文件
<your project>/platforms/android/src/main/AndroidManifest.xml
中<application>
标签内添加以下行<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>
-
在
<your project>/app/App_Resources/Android/AndroidManifest.xml
文件中<application>
标签内添加步骤 2 中的相同行 -
将
google-services.json
文件粘贴到<your project>/platforms/android/
文件夹中 -
打开
<your project>/platforms/android/build.gradle
:在文件顶部提到的依赖项中添加以下内容(在classpath "com.android.tools.build:gradle:2.2.3"
下方):classpath "com.google.gms:google-services:3.1.1"
在apply plugin: "com.android.application"
下方添加以下内容:apply plugin: "com.google.gms.google-services"
-
在 applozic 登录成功后调用 PushNotificationTask,如下所示
applozicChat.registerForPushNotification(function(response){
console.log("push success : " + response);
}, function(response){
console.log("push failed : " + response);
});
注意:每次您移除并添加 android 平台时,都需要遵循步骤 1、2、4 和 5。
iOS
-
从此 delegate.ts 链接 下载 delegate.ts 文件,并将其粘贴到
your project folder-->app-->delegate.ts
下 -
从 app.ts 链接 下载 app.ts 文件,并用它替换您的项目中的 app.ts 文件,如果您有任何更改,则可以仅从 app.ts 文件链接合并所需更改
注意:上述针对Android和iOS的推送通知设置是在您项目中未使用原生脚本推送插件的情况下的设置。