English | 简体中文
For the overview and console prerequisites (create an app / obtain keys / enable push and configure vendor channels), please read the parent document first: ../README.md. This document focuses only on the Unity client-side integration.
The Tencent Cloud TIMPush offline-push Unity experience demo (project under pushdemo/). This project is a clean template with nothing configured: the SDKAppID, AppKey, Android vendor channels, and iOS certificate ID / App Group all need to be configured by you as described below before it can build and run.
- You have completed the Common Prerequisites (Console) in the parent document, obtained the SDKAppID / AppKey, and enabled push and configured the vendor offline channels you need in the console.
- Unity is installed, plus the Android / iOS build environment, and a real device is ready (the Editor cannot verify push; it must be a real device).
unity/pushdemo/
├── Assets/
│ ├── TIMPush/ # TIMPush SDK source (PushManager / platform impl)
│ ├── TIMPushExample/ # demo scene (Scenes/PushDemo.unity) + Scripts/PushTest.cs
│ └── Plugins/ # Android gradle templates / iOS UnityIMPush.mm
├── Packages/
└── ProjectSettings/
Open unity/pushdemo/ with Unity, and open the Assets/TIMPushExample/Assets/Scenes/PushDemo.unity scene. The TIMPush SDK is already integrated as source under Assets/TIMPush/.
Assets/TIMPushExample/Assets/Scripts/PushTest.cs reads the SDKAppID / AppKey / RegistrationID from the on-screen input fields at runtime, then calls:
PushManager.RegisterPush(sdkAppId, appKey, new PushCallback(onSuccess, onError));Enter your SDKAppID and AppKey in the running demo UI, or change the defaults in the scene's input fields.
- Enable the vendor channels you need in
Assets/Plugins/Android/launcherTemplate.gradle, add the classpath / repositories inbaseProjectTemplate.gradleandsettingsTemplate.gradle(Xiaomi / Huawei / Honor / OPPO / vivo / Meizu / FCM), and fill Honor / vivo APPID / APPKEY. - Place
timpush-configs.jsonunderAssets/Plugins/Android/, and the Huawei / Honor / FCM json files underAssets/Plugins/Android/JsonConfigs/. - In
Player Settings > Publishing Settings > Build, tickCustom Main Gradle Template/Custom Base Gradle Template/Custom Gradle Settings Template.
- Implement
businessID(the certificate ID from the console) andapplicationGroupIDinAssets/Plugins/iOS/UnityIMPush.mm. - After exporting the Xcode project, enable the
Push Notificationscapability; for delivery statistics configure the Notification Service Extension.
Build to a real device. After registration succeeds, the demo UI shows the RegistrationID; receiving a push means the whole flow works.
PushTest.cs: demonstratesRegisterPush/UnRegisterPush/GetRegistrationID/SetRegistrationID/AddPushListener/RemovePushListener/ForceUseFCMPushChannel/DisablePostNotificationInForeground.- The push listener callbacks are
onRecvPushMessage/onRevokePushMessage/onNotificationClicked. - If you have integrated IM and call
RegisterPushafter IM login succeeds, passappKeyas null to avoid kicking the IM account offline.