# Unity SDK 快速入门

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

## 先决条件

要将 Pushwoosh Unity SDK 集成到您的应用中，您需要满足以下条件：

<TranslatedFragment id="prerequisites-plugins-unity" />

## 下载示例项目

克隆示例项目仓库：

```bash
git clone https://github.com/Pushwoosh/pushwoosh-unity-sample.git
```

## 配置项目

打开 **Assets/Scripts/PushNotificator.cs** 并设置 Pushwoosh 初始化值：

```csharp title="Assets/Scripts/PushNotificator.cs"
Pushwoosh.ApplicationCode = "XXXXX-XXXXX";
Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
```

将 `ApplicationCode` 和 `FcmProjectNumber` 的值替换为您的 **Pushwoosh App Code** 和 **Firebase Project Number**。

### iOS

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

在 Unity 中，前往 **Edit > Project Settings > Player > iOS > Other Settings** 并将 **Bundle Identifier** 设置为您的 bundle ID（例如，`com.example.pushwoosh`）。

###### 2. 构建并安装依赖项

从 Unity 构建 iOS 项目。然后导航到生成的 Xcode 项目目录并安装 CocoaPods 依赖项：

```bash
cd ios && pod install
```

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

在 Xcode 中打开 **ios/Unity-iPhone.xcworkspace** 文件。
在您的 `Info.plist` 中添加 [Pushwoosh Device API Token](/zh/developer/api-reference/api-access-token/#device-api-token)：

```xml title="Info.plist"
<key>Pushwoosh_API_TOKEN</key>
<string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>
```

### Android

###### 1. 设置包名

在 Unity 中，前往 **Edit > Project Settings > Player > Android > Other Settings** 并将 **Package Name** 设置为您的应用的包名（例如，`com.example.pushwoosh`）。

###### 2. 添加 google-services.json

将您的 `google-services.json` 文件复制到 Unity 项目的 **Assets** 目录中。

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

在您的 `Assets/Plugins/Android/AndroidManifest.xml` 中，在 `<application>` 标签内添加 [Pushwoosh Device API Token](/zh/developer/api-reference/api-access-token/#device-api-token)：

```xml title="AndroidManifest.xml"
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />
```

<Aside type="caution">
请确保在您的 Pushwoosh Control Panel 中为该 token 授予对正确应用的访问权限。[了解更多](/zh/developer/api-reference/api-access-token/#edit-token)
</Aside>

## 运行项目

1. 构建并运行项目。
2. 点击 **Register for push notifications** 按钮。
3. 授予推送通知权限。设备将在 Pushwoosh 中注册。

## 发送推送通知

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