nativeScript-batch-notifications
Nativescript 批量插件用于通知。
npm i --save nativescript-batch-notifications

Nativescript 批量插件

欢迎使用 Batch 的 Nativescript 插件!
Batch 是一个功能齐全的移动参与平台,可在 iOS、Android 和移动网站上执行 CRM 战略。
此插件的目的在于管理 Android 和 iOS 上的推送通知、应用内消息等。
此存储库包含插件的源代码和演示应用程序。

安装

NPM

npm i nativescript-batch-notifications

先决条件 / 要求

首先,您必须 创建一个 Batch 账户
然后需要为每个平台进行配置;
此过程在 Batch 官方文档中通过简单步骤进行解释。
IOS 设置
Android 设置
当您添加 Firebase Android 项目时,下载 google-services.json,并将其添加到 NativeScript 项目的 app/App_Resources/Android/google-services.json 中。

要快速开始使用演示应用程序:

  • 覆盖演示目录中 'package.json' 中的 bundle id。
  • 使用由您的 Batch 账户生成的 API 密钥覆盖 'app.ts' 文件(用于 IOS)和 'application.android.ts' 文件(用于 Android)中的 API 密钥。

工作原理

一图胜千言 全局图

Android 初始化

我们必须重写 OnCreate 方法。
为此,将 AndroidManifest 中的应用程序名称值从 com.tns.NativeScriptApplication 更改为类似 org.myApp.Application 的内容。
然后,在根目录中创建一个名为 'application.android.ts' 的 TypeScript 文件,并输入以下代码。

const firebase = require("nativescript-plugin-firebase");
// @ts-ignore
import { Batch } from 'nativescript-batch-notifications';

@JavaProxy("org.myApp.Application")
class Application extends android.app.Application {
    public onCreate(): void {
        super.onCreate();
        let batch = new Batch();
        batch.init('YOUR_BATCH_API_KEY');
        this.registerActivityLifecycleCallbacks(batch.activityLifeCycleHelper());
        firebase.init().catch(e => console.dir(e));
    }
}

IOS 初始化

我们必须设置一个自定义代理;覆盖根目录中的 app.ts,并输入以下代码。

import * as app from "tns-core-modules/application";
import {run as applicationRun} from "tns-core-modules/application";
// @ts-ignore
import { Batch } from 'nativescript-batch-notifications';

if (app.ios) {
class customDelegate extends UIResponder implements UIApplicationDelegate {
    public static ObjCProtocols = [UIApplicationDelegate];

    applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary<string, any>): boolean {
        console.log("IOS Entered");
        let batch = new Batch();
        batch.initIOS('YOUR_BATCH_API_KEY');
        return true;
    }
}
app.ios.delegate = customDelegate;
applicationRun({ moduleName: "main-page" });
} else {
applicationRun({ moduleName: "app-root" });
}

重要提示 !!

  • (Android) 在本插件版本中,我们假设已安装 nativescript firebase 插件;这将在未来的版本中修复。
  • (IOS) 在生成 xcode 项目时,您必须在“功能”选项卡中切换“推送通知”。

许可证

MIT