Cordova SDK 快速入门
通过这个快速简单的示例,开始使用 Pushwoosh Cordova SDK。
前提条件
Anchor link to要将 Pushwoosh Cordova SDK 集成到您的应用程序中,您需要以下内容:
下载示例项目
Anchor link to# Clone the SDK repository and navigate to the example projectgit clone https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git
# Navigate to example directorycd pushwoosh-phonegap-plugin/example/newdemo/配置项目
Anchor link to安装依赖项:
npm i添加 Pushwoosh 插件:
cordova plugin add ../../ --link --nofetch打开 www/js/index.js 并更新 pushwoosh.onDeviceReady 调用:
pushwoosh.onDeviceReady({ appid: "XXXXX-XXXXX", projectid: "XXXXXXXXXXXXXXX"});将 appid 和 projectid 值替换为您的 Pushwoosh App Code 和 Firebase Project Number。
1. 设置 Bundle Identifier
Anchor link to在 Xcode 中打开 platforms/ios/newdemo.xcworkspace 文件。
为每个目标设置 Bundle Identifier:
newdemo:您的应用程序的包名。(例如com.example.pushwoosh)
2. 添加功能
Anchor link to要启用 Push Notifications(推送通知),您需要添加某些功能。
在 Signing & Capabilities(签名与功能)部分,添加以下功能:
Push Notifications(推送通知)Background Modes(后台模式)。添加此功能后,勾选Remote notifications(远程通知)复选框。
3. 设置 API Token
Anchor link to在您的 ios/newdemo/Info.plist 中,将 Pushwoosh_API_TOKEN 键设置为 Pushwoosh Device API Token。
Android
Anchor link to1. 设置 google-services.json
Anchor link to将您的 google-services.json 文件复制到项目的根目录。
2. 设置包名
Anchor link to打开 android/app/build.gradle 并将 applicationId 设置为您的应用程序的包名。(例如 com.example.pushwoosh)
3. 设置 API Token
Anchor link to打开您的 android/app/src/main/AndroidManifest.xml 文件,并在 <application> 标签内添加以下元数据:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__" />将 __YOUR_PUSHWOOSH_DEVICE_API_TOKEN__ 替换为您的 Pushwoosh Device API Token。
运行项目
Anchor link to- 构建并运行项目。
- 切换 Register for notifications(注册通知)开关。
- 授予推送通知权限。设备将注册到 Pushwoosh。
发送推送通知
Anchor link to返回 Pushwoosh Control Panel(控制面板),并向您注册的设备 发送推送通知。