Unity SDK 快速入门
通过这个快速简单的示例开始使用 Pushwoosh Unity SDK。
先决条件
Anchor link to要将 Pushwoosh Unity SDK 集成到您的应用中,您需要满足以下条件:
下载示例项目
Anchor link to克隆示例项目仓库:
git clone https://github.com/Pushwoosh/pushwoosh-unity-sample.git配置项目
Anchor link to打开 Assets/Scripts/PushNotificator.cs 并设置 Pushwoosh 初始化值:
Pushwoosh.ApplicationCode = "XXXXX-XXXXX";Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";将 ApplicationCode 和 FcmProjectNumber 的值替换为您的 Pushwoosh App Code 和 Firebase 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 依赖项:
cd ios && pod install3. 设置 API Token
Anchor link to在 Xcode 中打开 ios/Unity-iPhone.xcworkspace 文件。
在您的 Info.plist 中添加 Pushwoosh Device API Token:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>Android
Anchor link to1. 设置包名
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:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />运行项目
Anchor link to- 构建并运行项目。
- 点击 Register for push notifications 按钮。
- 授予推送通知权限。设备将在 Pushwoosh 中注册。
发送推送通知
Anchor link to前往 Pushwoosh Control Panel 并向您注册的设备发送推送通知。