# Cordova SDK 快速入门

通过这个快速简单的示例开始使用 Pushwoosh Cordova SDK

## 前提条件

要将 Pushwoosh Cordova SDK 集成到您的应用程序中，您需要以下内容：

<TranslatedFragment id="prerequisites-plugins" />

## 下载示例项目

```bash
# 克隆 SDK 仓库并导航到示例项目
git clone https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git

# 导航到示例目录
cd pushwoosh-phonegap-plugin/example/newdemo/
```

## 配置项目

安装依赖项：

```bash
npm i
```

添加 Pushwoosh 插件：
```bash
cordova plugin add ../../ --link --nofetch
```

打开 **www/js/index.js** 并更新 `pushwoosh.onDeviceReady` 调用：

```javascript
pushwoosh.onDeviceReady({
    appid: "XXXXX-XXXXX"
});
```

将 `appid` 的值替换为您的 **Pushwoosh App Code**。

### iOS

###### 1. 设置 Bundle Identifier

在 Xcode 中打开 **platforms/ios/newdemo.xcworkspace** 文件。

为每个 target 设置 **Bundle Identifier**：

- `newdemo`：您的应用程序包名。（例如 com.example.pushwoosh）

###### 2. 添加功能

要启用推送通知，您需要添加某些功能。

在 Signing & Capabilities 部分，添加以下功能：
- `Push Notifications`
- `Background Modes`。添加此功能后，勾选 `Remote notifications` 复选框。

###### 3. 设置 API Token

在您的 `ios/newdemo/Info.plist` 中，将 `Pushwoosh_API_TOKEN` 键设置为 [Pushwoosh Device API Token](/zh/developer/api-reference/api-access-token/#device-api-token)

### Android

###### 1. 设置 google-services.json

将您的 `google-services.json` 文件复制到项目的根目录

###### 2. 设置包名

打开 **android/app/build.gradle** 并将 **applicationId** 设置为您的应用程序包名。（例如 `com.example.pushwoosh`）

###### 3. 设置 API Token

打开您的 **android/app/src/main/AndroidManifest.xml** 文件，并在 `<application>` 标签内添加以下元数据：

```xml title="AndroidManifest.xml"
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__" />
```
将 `__YOUR_PUSHWOOSH_DEVICE_API_TOKEN__` 替换为您的 [Pushwoosh Device API Token](/zh/developer/api-reference/api-access-token/#device-api-token)。

## 运行项目

1. 构建并运行项目。
2. 切换 **Register for notifications** 开关。
3. 授予推送通知权限。设备将在 Pushwoosh 中注册。

## 发送推送通知

返回 Pushwoosh Control Panel 并向您注册的设备[发送推送通知](/zh/product/messaging-channels/push-notifications/send-push-notifications/one-time-push)。