跳到内容

Unity SDK 快速入门

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

前提条件

Anchor link to

要将 Pushwoosh Unity SDK 集成到您的应用中,您需要以下内容:

下载示例项目

Anchor link to

克隆示例项目仓库:

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

配置项目

Anchor link to

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

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

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

1. 设置 Bundle Identifier
Anchor link to

在 iOS 构建配置文件中,将 Bundle Identifier 设置为您的 bundle ID(例如 com.example.pushwoosh)。

2. 安装依赖项
Anchor link to

完成 iOS 构建后,导航到 ios 目录并安装依赖项:

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

在 Xcode 中打开 ios/Unity-iPhone.xcworkspace 文件。 在您的 ios/Unity-iPhone/Info.plist 中,将 __PUSHWOOSH_DEVICE_API_TOKEN__ 键设置为 Pushwoosh Device API Token

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

在 Android 构建配置文件中,将 Package Name 设置为您的应用包名(例如 com.example.pushwoosh)。

2. 设置 google-services.json
Anchor link to

将您的 google-services.json 文件复制到 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__" />

重要提示: 请确保在您的 Pushwoosh 控制面板中授予该令牌对正确应用的访问权限。 了解更多

运行项目

Anchor link to
  1. 构建并运行项目。
  2. 点击“注册推送通知”按钮。
  3. 授予推送通知权限。设备将注册到 Pushwoosh。

发送推送通知

Anchor link to

返回 Pushwoosh 控制面板,并向您注册的设备 发送推送通知