跳到内容

Unity SDK 快速入门

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

先决条件

Anchor link to

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

下载示例项目

Anchor link to

克隆示例项目仓库:

Terminal window
git clone https://github.com/Pushwoosh/pushwoosh-unity-sample.git

配置项目

Anchor link to

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

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

ApplicationCodeFcmProjectNumber 的值替换为您的 Pushwoosh App CodeFirebase Project Number

1. 设置 Bundle Identifier
Anchor link to

在 Unity 中,前往 Edit > Project Settings > Player > iOS > Other Settings 并将 Bundle Identifier 设置为您的 bundle ID(例如,com.example.pushwoosh)。

2. 构建并安装依赖项
Anchor link to

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

Terminal window
cd ios && pod install
3. 设置 API Token
Anchor link to

在 Xcode 中打开 ios/Unity-iPhone.xcworkspace 文件。 在您的 Info.plist 中添加 Pushwoosh Device API Token

Info.plist
<key>Pushwoosh_API_TOKEN</key>
<string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>
1. 设置包名
Anchor link to

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

2. 添加 google-services.json
Anchor link to

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

3. 设置 API Token
Anchor link to

在您的 Assets/Plugins/Android/AndroidManifest.xml 中,在 <application> 标签内添加 Pushwoosh Device API Token

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

运行项目

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

发送推送通知

Anchor link to

前往 Pushwoosh Control Panel 并向您注册的设备发送推送通知