npm i --save @leoantares/ns8-batch-notifications
- 版本: 1.1.1
- GitHub: https://github.com/alexcode/ns8-plugins
- NPM: https://npmjs.net.cn/package/%40leoantares%2Fns8-batch-notifications
- 下载量
- 昨天: 0
- 上周: 0
- 上个月: 0
@leoantares/ns8-batch-notifications
ns plugin add @leoantares/ns8-batch-notifications
Nativescript 批量插件
欢迎使用 Batch 的 Nativescript 插件!
Batch 是一个完整的移动参与平台,可在 iOS、Android 和移动网站上执行 CRM 策略。
此插件的目的在于管理推送通知、应用内消息等,针对 Android 和 IOS。
此存储库包含插件的源代码和一个演示应用程序。
此插件是从 nativescript-batch-notifications 更新分支。
安装
NPM
yarn ns8-batch-notifications
npm i ns8-batch-notifications
先决条件 / 要求
首先,您必须 创建一个 batch 账户;
然后需要为每个平台进行配置;
这个过程在 batch 官方文档中有简单的步骤说明。
IOS 配置
Android 配置
当您添加 Firebase Android 项目时,请下载 google-services.json
并将其添加到 NativeScript 项目的 app/App_Resources/Android/google-services.json
中。
快速开始使用演示应用程序
- 在演示目录的
package.json
中覆盖 bundle id。 - 在
.env
文件中添加由您的 batch 账户生成的 API 密钥。
Android 初始化
我们必须覆盖 OnCreate 方法。
为此,将 AndroidManifest 中的应用程序名称值从 com.tns.NativeScriptApplication 更改为类似 org.myApp.Application 的内容。
然后,在根目录中创建一个名为 'application.android.ts' 的 TypeScript 文件,并输入以下代码。
const firebase = require('@nativescript/firebase');
// @ts-ignore
import { BatchNS } from 'nativescript-batch-notifications';
@NativeClass()
@JavaProxy('org.myApp.Application')
class Application extends android.app.Application {
public onCreate(): void {
super.onCreate()
const batch = new BatchNS(process.env.BASH_ANDROID_KEY);
this.registerActivityLifecycleCallbacks(batch.native.activityLifeCycleHelper());
firebase.init().catch(console.dir);
}
}
您还必须在您的 webpack.config.js
中添加以下内容。
webpack.chainWebpack(config => {
if (webpack.Utils.platform.getPlatformName() === 'android') {
// make sure the path to the applicatioon.android.(js|ts)
// is relative to the webpack.config.js
// you may need to use `./app/application.android if
// your app source is located inside the ./app folder.
config.entry('application').add('./app/application.android')
}
})
IOS 初始化
我们必须设置一个自定义代理;在根目录中覆盖 app.ts,输入以下代码。
import { Application, isIOS } from "@nativescript/core";
// @ts-ignore
import { BatchNS } from "nativescript-batch-notifications";
if (isIOS) {
@NativeClass
class MyDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary<any, any>): boolean {
new BatchNS(process.env.BATCH_IOS_KEY, false);
return true;
}
}
Application.ios.delegate = MyDelegate;
}
重要提示 !!
- (Android) 在此插件版本中,我们假设已安装 nativescript firebase 插件;这将在未来的版本中修复。
- (IOS) 在生成 xcode 项目时,您 MUST 在功能选项卡中切换 'Push Notifications'。
许可
Apache 许可证版本 2.0