Unity
How to integrate Pushwoosh SDK into your Unity project
Supports iOS, Android, Amazon, Windows Store Apps (Windows 8.1/Phone 8.1/Windows 10)
Download Plugin Download Sample Plugin Docs
To integrate Pushwoosh into your Unity application you need to do simple following steps:
Get the
google-services.json
from your Firebase console as described here and locate it to your project's Assets folder. Package name of your app should be added to your Firebase project and persist in thegoogle-services.json
file.Import Unity push notification plugin into your Assets folder in Unity.
AndroidManifest.xml changes
Merge contents of Assets/Plugins/Android/PushwooshAndroidManifest.xml into Assets/Plugins/Android/AndroidManifest.xml. If you don't already have an Android Manifest, rename PushwooshAndroidManifest.xml to AndroidManifest.xml. Replace PACKAGE_NAME with your project package. Note that in Unity it is called ‘Bundle Identifier’.
1. Create PushNotificator.cs script and attach it to Camera Object in the scene.
That’s it! How easy is that?
ApplicationCode and FcmProjectNumber should be set before first Pushwoosh.Instance method call.
2. If you need to use Geozones, go to Assets/Pushwoosh/Editor/PushwooshDependencies.xml and uncomment the following lines:
Now you can start and stop tracking Geozones:
Since iOS manages push notifications at the OS level, make sure to include the Pushwoosh Notification Service Extension to track the delivery of push notifications for your iOS app. Learn how to add it
Enable Push Notifications in the Capabilities section.
Enable Remote notifications for Background Modes in the Capabilities section.
Amazon API Key
Get the API KEY from Amazon according to the Amazon guide. For a pre-release or “debug” version of your app, you must create an API Key and store it as the only data in a file named api_key.txt . The api_key.txt file must be located inside the Assets folder for your project. Note: ADM cannot recognize your API Key if it contains any spaces or line breaks. For a release or “production” version of your app, you may not need to create an API Key. Only if you sign the release version of your app using your own certificate, must you create an additional API Key for the release version of your app. Otherwise, if you allow Amazon to sign your app on your behalf, you do not need to create an additional API Key.
You might need to select WSAPlayer platform for the libraries in Plugins/WSA as per screenshot below.
You also need to Associate App with the Store in exported Visual Studio project. And don't forget to set Notifications->Toast Capable in the project manifest.
Issues with Unity projects with the Pushwoosh plugin installed
If you face the error like the one shown in the picture below, it might be caused by the Unity framework issue with the projects with 3rd-party plugins.
That’s what the Unity resolution note on this issue says:
At some point, UnityFramework runtime together with plugins is loaded at run time by dyld/NSBundle.load. Please keep that in mind while developing a plugin.
Any API-rich initialization on +(load), attribute(constructor), and global object construction code paths should be moved to a later phase preferably after UnityFramework is loaded, and even better when Unity is initialized.
Simple plain data initialization is safe, but API-rich calls that deal with other os parts especially networking and user interface APIs might lead to deadlock leading to watchdog termination.
By doing delayed/lazy initialization you can get better control over initialization order, you can reduce the application load time, and most importantly you avoid possible deadlock.
Possible workaround:
By default, UnityFramework.framework is embedded in Unity-iPhone target and it is not linked with it, UnityFramework is loaded later at runtime and some plugins are sensitive to this initialization path.
Go to Unity-iPhone / Build Phases / Link Binary with Libraries build section and add UnityFramework.framework.
UnityFramework will be loaded at the same time as the main executable.
Share your feedback with us
Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.
Last updated