-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [3.0.0-pre.1] - 2022-12-16 ### Fixed Fixed a bug preventing the `notificationOpened` event from being sent after opening a notification while the app was fully closed ### Changes - The following classes have been changed to `internal`: - `InsertPushNotificationDependenciesIntoGradleScript` - `IOSRichPushNotificationPostProcess` - `IOSBasicPushNotificationPostProcess` - `PushSettingsProvider` - `PushNotificationEditorGameService` - `PushNotificationAnalytics` - Moved `IPushNotificationsAnalytics` to it's own file. - Change `PushNotificationsService` to use the `IPushNotificationsAnalytics` interface instead of directly using the `PushNotificationsAnalytics` class. - Bumped the Analytics SDK version from `4.0.0-pre.2` to `4.3.0` - Bumped the Core Package SDK version from `1.2.0` to `1.4.0` - Dashboard project link now available in settings panel - Renamed the following fields in `PushNotificationSettings` (Values will be retained): - `androidApiKey` -> `firebaseWebApiKey` - `androidSenderId` -> `firebaseProjectNumber` - `androidApplicationId` -> `firebaseAppID` - `androidProjectId` -> `firebaseProjectID` ### Removed - Removed the deprecated `PushNotifications` class. - Removed obsolete `PushNotificationSettings` properties. ### Known Issues - Notifications received while the app is opened will automatically trigger the `notificationOpened` event even before they are opened - `didLaunch` property sent with `notificationOpened` event not fully accurate - Devices running Android 13 will not receive notifications until the player grants permission. Permission won’t be requested until the device receives a notification for the first time.
- Loading branch information
Unity Technologies
committed
Dec 16, 2022
1 parent
72d9171
commit 18b1637
Showing
43 changed files
with
359 additions
and
679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,2 @@ | ||
# Push Notifications SDK documentation | ||
|
||
The Push Notifications SDK allows you to send push notification campaigns, including rich push notifications with images to your users. | ||
|
||
## Platform support | ||
|
||
This SDK supports both iOS and Android. iOS 10+ and Android SDK >= 26 (Oreo) are supported. | ||
|
||
## Quick Start | ||
|
||
The SDK comes with a sample script that will register for push notifications. Add this to your project and set the relevant settings in the editor under Project Settings. | ||
|
||
## Registering for Push Notifications | ||
|
||
To register for push notifications, three steps are required. | ||
|
||
First, you need to populate some settings in the editor. These can be found in Project Settings > Services > Push Notifications. | ||
|
||
Next, you need to initialise Unity Services, so that the required analytics events can be sent to Unity Analytics. You also need to implement the privacy flow, as detailed in the Analytics documentation, for the required events to be sent correctly. | ||
|
||
You can then register for notifications. Ideally, to ensure no notifications are missed, this should be done in the startup code for your game. However, note that on first registration on iOS a user will be shown a permission request, so also ensure this call is made at a convenient place in your game. The SDK will handle the showing of notification content, including images, titles and message body. | ||
|
||
A full code sample is shown below. | ||
|
||
```cs | ||
await UnityServices.InitializeAsync(); | ||
// Note: This is the minimum required in Analytics version 3.0.0 and above to ensure the events with the push notification data are sent correctly. | ||
// In a real game you would need to handle privacy consent states here, see the Analytics documentation for more details. | ||
await AnalyticsService.Instance.CheckForRequiredConsents(); | ||
|
||
try | ||
{ | ||
string pushToken = await PushNotificationService.Instance.RegisterForPushNotificationsAsync(); | ||
|
||
PushNotificationService.Instance.OnNotificationReceived += notificationData => | ||
{ | ||
Debug.Log("Received a notification!"); | ||
}; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.Log("Failed to retrieve a push notification token."); | ||
} | ||
``` | ||
|
||
### Notification received callbacks | ||
|
||
You can register a delegate to receive a C# event callback when a notification is received, if you wish to perform custom behavior at that point. To do this, add a delegate / method callback to `PushNotifications.OnNotificationReceived` as shown in the sample above. | ||
|
||
### Push Notification settings | ||
|
||
The SDK requires a number of settings in order to function correctly. Some settings are only used on a certain platform, indicated in the setting name. The following settings can be set: | ||
|
||
* AndroidApiKey: The API key for a Firebase project to be used for Android's Firebase Cloud Messaging API. This can be found in your Firebase dashboard. | ||
* AndroidSenderId: The sender ID to be used for Android's Firebase Cloud Messaging. This can be found in your Firebase dashboard. | ||
* AndroidApplicationId: The application ID for a Firebase application to be used for Android's Firebase Cloud Messaging API. This can be found in your Firebase dashboard. | ||
* AndroidProjectId: The project ID for a Firebase project to be used for Android's Firebase Cloud Messaging API. This can be found in your Firebase dashboard. | ||
|
||
These settings are set in Project Settings -> Services -> Push Notifications. | ||
|
||
### Analytics | ||
|
||
The SDK will record two analytics events: | ||
|
||
* `notificationServices`: This event is recorded whenever a new token is registered on the client. It contains the push token and is used to register this token with the backend service. This allows you to send notifications from the Unity Dashboard, and is required for proper functionality of this product. | ||
* `notificationOpened`: This event is recorded whenever a notification is opened by a user. It contains data regarding which campaign and cohort the user was in, and whether the app was launched from the notification. | ||
|
||
#### Analytics only mode | ||
|
||
*WARNING: This section is only applicable if you're trying to use the Unity Dashboard Push Notification service alongside a separate Push Notification implementation. For most users this section is not required or recommended as it'll lead to reduced functionality of the product* | ||
|
||
It's possible to integrate the SDK with an existing push notification service if required. To do so, do not call the registration methods as indicated above, and instead use the two methods in `PushNotificationService.Instance.Analytics` alongside your existing implementation. | ||
|
||
`RecordPushTokenUpdated` should be called when you receive a new push token for a device. Note that the OS may create a new token at multiple points in the app's lifecycle, so call this whenever the token changes, and not just at startup. | ||
|
||
`RecordNotificationOpened` should be called when a notification is opened. It takes a dictionary that is the data the notification payload contained, and a boolean flag to indicate whether the app was launched from the notification or not. | ||
|
||
Note that this should allow you to send and schedule notifications from the Unity Dashboard. However, it greatly depends on the other push notification implementation you have implemented, and may lead to missing images or other content in notifications, so it's strongly recommended to use the standard set up, with this SDK being the only Push Notification solution integrated, if possible. | ||
Please consult the full manual on https://docs.unity.com/push-notifications/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.