Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [4.0.1] - 2024-10-16

### Changed
- Bug fix associated with the `registerForPushNotificationsAsync` method hanging for Android devices in some cases.
  • Loading branch information
Unity Technologies committed Oct 16, 2024
1 parent 16b2a15 commit 50dc48a
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 10 deletions.
1 change: 1 addition & 0 deletions .signature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"timestamp":1732620451,"signature":"DvQlluzS1Ol1+QX4bwEz1e7YPjeJS0FgRw+5dgmHkn5tXp0/sX8pk+sO+yzO7lvJgxMp9MoBZDumue3E7HowKvl4KBWSme6b67TfOsjQmWBrqedGGt5A3uV74gHyi65SN9o3vPWM+63PRYbwDTyV8WzVtxsqANxYy2JxxXOVHOervjfkhDqSXRDjQBRraKazzNLKzaKfbVH51YsvWlu2AkJCfxqyQYyrzcaVUv6OPYdJ09QA2W/IugooX6y0tiP+9lRM1mUkWP0RiX168CHdQOWO4PC6eFxttQEqEXdtghdXmF78spJ8ualK2BwXu7/W3OczcXVlUUmQTDmOsTMzBNKpHwjGo398AwchYTUIdy7TOlrILuNqifYT5lAhVwdLU6CWSn9WXCYjHGW3DsjQIW5PTLEmL9EpnlvStKkfu07uULmklDhdoWvHY0uB5QyPShYaDZlwoXbPpaC7fBIECSZP0qpc8aiw8EIR0HufBlVcIo6V+bfGNAXU2dve6ymX","publicKey":"LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQm9qQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FZOEFNSUlCaWdLQ0FZRUFzdUhXYUhsZ0I1cVF4ZEJjTlJKSAordHR4SmoxcVY1NTdvMlZaRE1XaXhYRVBkRTBEMVFkT1JIRXNSS1RscmplUXlERU83ZlNQS0ZwZ1A3MU5TTnJCCkFHM2NFSU45aHNQVDhOVmllZmdWem5QTkVMenFkVmdEbFhpb2VpUnV6OERKWFgvblpmU1JWKytwbk9ySTRibG4KS0twelJlNW14OTc1SjhxZ1FvRktKT0NNRlpHdkJMR2MxSzZZaEIzOHJFODZCZzgzbUovWjBEYkVmQjBxZm13cgo2ZDVFUXFsd0E5Y3JZT1YyV1VpWXprSnBLNmJZNzRZNmM1TmpBcEFKeGNiaTFOaDlRVEhUcU44N0ZtMDF0R1ZwCjVNd1pXSWZuYVRUemEvTGZLelR5U0pka0tldEZMVGdkYXpMYlpzUEE2aHBSK0FJRTJhc0tLTi84UUk1N3UzU2cKL2xyMnZKS1IvU2l5eEN1Q20vQWJkYnJMbXk0WjlSdm1jMGdpclA4T0lLQWxBRWZ2TzV5Z2hSKy8vd1RpTFlzUQp1SllDM0V2UE16ZGdKUzdGR2FscnFLZzlPTCsxVzROY05yNWdveVdSUUJ0cktKaWlTZEJVWmVxb0RvSUY5NHpCCndGbzJJT1JFdXFqcU51M3diMWZIM3p1dGdtalFra3IxVjJhd3hmcExLWlROQWdNQkFBRT0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg"}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.0.1] - 2024-10-16

### Changed
- Bug fix associated with the `registerForPushNotificationsAsync` method hanging for Android devices in some cases.

## [4.0.0] - 2024-09-27

### Changed
Expand Down
6 changes: 6 additions & 0 deletions Documentation~/filter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiRules:
- exclude:
hasAttribute:
uid: System.ComponentModel.EditorBrowsableAttribute
ctorArguments:
- System.ComponentModel.EditorBrowsableState.Never
3 changes: 3 additions & 0 deletions Editor/Settings/PushNotificationEditorGameService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using Unity.Services.Core.Editor;
using Unity.Services.Core.Editor.OrganizationHandler;
using UnityEditor;

namespace Unity.Services.PushNotifications.Editor
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public struct PushNotificationIdentifier : IEditorGameServiceIdentifier
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public string GetKey() => "Push Notifications";
}

Expand Down
Binary file modified Plugins/Android/PushNotificationsAndroidLib-release.aar
Binary file not shown.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Push Notifications SDK

> Note: This product is in open beta, for more information please contact us.
This package adds support for push notifications to your project, allowing you to send push notification campaigns to your users.
14 changes: 14 additions & 0 deletions Runtime/Analytics/IPushNotificationsAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@

namespace Unity.Services.PushNotifications
{
/// <summary>
/// This interface is no longer required. Notification events are recorded for you automatically when you register for push notifications
/// using RegisterForPushNotificationsAsync.
/// </summary>
[Obsolete("This interface should not be used. It will be deleted in the future version. Notification events are recorded for you automatically.")]
public interface IPushNotificationsAnalytics
{
/// <summary>
/// RecordPushTokenUpdated is no longer required. Notification events are recorded for you automatically when you register for push notifications using <see cref="RegisterForPushNotificationsAsync"/>.
/// </summary>
/// <param name="pushToken">Please use the RegisterForPushNotificationsAsync method</param>
void RecordPushTokenUpdated(string pushToken);

/// <summary>
/// RecordNotificationOpened is no longer required. Notification events are recorded for you automatically when you register for push notifications using <see cref="RegisterForPushNotificationsAsync"/>.
/// </summary>
/// <param name="payload">Please use the RegisterForPushNotificationsAsync method</param>
/// <param name="didLaunch">Please use the RegisterForPushNotificationsAsync method</param>
void RecordNotificationOpened(Dictionary<string, object> payload, bool didLaunch);
}

Expand Down
7 changes: 7 additions & 0 deletions Runtime/IPushNotificationsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Unity.Services.PushNotifications
{
/// <summary>
/// Interface representing a collection of methods to interact with the Push Notifications service.
/// </summary>
public interface IPushNotificationsService
{
/// <summary>
Expand All @@ -16,6 +19,10 @@ public interface IPushNotificationsService
/// </summary>
public event Action<Dictionary<string, object>> OnRemoteNotificationReceived;

/// <summary>
/// This is no longer required. Notification events are recorded for you automatically when you register for push notifications
/// using <see cref="RegisterForPushNotificationsAsync"/>.
/// </summary>
[Obsolete("Do not use this. It will be removed in a future version. Events are recorded for you automatically.")]
public IPushNotificationsAnalytics Analytics { get; }

Expand Down
20 changes: 19 additions & 1 deletion Runtime/Platforms/AndroidPushNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public void OnApplicationPause(bool isPaused)
/// <returns>The push notification token for this device</returns>
public Task<string> RegisterForPushNotifications(PushNotificationSettings settings)
{
// Check if a Task exists before re instantiating a new TaskCompletionSource
if (s_RegisterTcSource != null)
{
return s_RegisterTcSource.Task;
}
s_RegisterTcSource = new TaskCompletionSource<string>();

if (String.IsNullOrEmpty(settings.firebaseWebApiKey) ||
String.IsNullOrEmpty(settings.firebaseAppID) ||
String.IsNullOrEmpty(settings.firebaseProjectNumber) ||
Expand All @@ -57,7 +64,6 @@ public Task<string> RegisterForPushNotifications(PushNotificationSettings settin
throw new Exception("UGS Push Notifications is missing Android settings - make sure these are set in the editor Project Settings");
}

s_RegisterTcSource = new TaskCompletionSource<string>();
m_Container.StartCoroutine(
RequestAuthorization(
settings.firebaseWebApiKey,
Expand All @@ -76,6 +82,11 @@ IEnumerator RequestAuthorization(string firebaseApiKey, string firebaseSenderId,
yield return null;
}

if (s_RegisterTcSource == null)
{
yield return null;
}

switch (request.Status)
{
case PermissionStatus.Allowed:
Expand All @@ -84,6 +95,7 @@ IEnumerator RequestAuthorization(string firebaseApiKey, string firebaseSenderId,
case PermissionStatus.Denied:
case PermissionStatus.DeniedDontAskAgain:
s_RegisterTcSource.TrySetException(new Exception($"Authorization request was denied"));
s_RegisterTcSource = null;
break;
}
}
Expand All @@ -106,7 +118,12 @@ void InitializePushNotifications(string firebaseApiKey, string firebaseSenderId,
}
catch (Exception e)
{
if (s_RegisterTcSource == null)
{
return;
}
s_RegisterTcSource.TrySetException(new Exception($"Failed to initialize Push Notification Plugin {e.Message}"));
s_RegisterTcSource = null;
}
}

Expand Down Expand Up @@ -138,6 +155,7 @@ public Dictionary<string, object> CheckForAppLaunchByNotification()
void OnTokenReceived(string token)
{
s_RegisterTcSource.TrySetResult(token);
s_RegisterTcSource = null;
}

// Implementing the UnityRemoteNotificationsCallback from the Plugin
Expand Down
16 changes: 14 additions & 2 deletions Runtime/Platforms/iOSPushNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ public void Initialize(IPushPlatformCallbacks callbacks)
/// <returns>The push notification token for this device</returns>
public Task<string> RegisterForPushNotifications(PushNotificationSettings settings)
{
// NOTE: Settings is only required by Android, but is taken to ensure a consistent interface

// Check if a Task exists before re instantiating a new TaskCompletionSource
if (s_RegisterTcSource != null)
{
return s_RegisterTcSource.Task;
}
s_RegisterTcSource = new TaskCompletionSource<string>();

// NOTE: Settings is only required by Android, but is taken to ensure a consistent interface
m_Container.StartCoroutine(RequestAuthorization(AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound));
return s_RegisterTcSource.Task;
}
Expand All @@ -49,13 +54,20 @@ IEnumerator RequestAuthorization(AuthorizationOption options)
yield return null;
}

if (s_RegisterTcSource == null)
{
yield return null;
}

if (request.Granted)
{
s_RegisterTcSource.TrySetResult(request.DeviceToken);
s_RegisterTcSource = null;
}
else
{
s_RegisterTcSource.TrySetException(new Exception("Authorization request was denied"));
s_RegisterTcSource = null;
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions Runtime/PushNotificationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ public class PushNotificationSettings : ScriptableObject
internal const string assetDirectory = resourcesContainer + "/" + resourcesDirectory;
internal const string fullAssetPath = assetDirectory + "/" + settingsAssetName + ".asset";

/// <summary>
/// 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.
/// </summary>
[Header("Android (Firebase) Settings")]
[FormerlySerializedAs("androidApiKey")]
public string firebaseWebApiKey;

/// <summary>
/// The sender ID to be used for Android's Firebase Cloud Messaging. This can be found in your Firebase dashboard.
/// </summary>
[FormerlySerializedAs("androidSenderId")]
public string firebaseProjectNumber;

/// <summary>
/// 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.
/// </summary>
[FormerlySerializedAs("androidApplicationId")]
public string firebaseAppID;

/// <summary>
/// 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.
/// </summary>
[FormerlySerializedAs("androidProjectId")]
public string firebaseProjectID;

Expand Down
7 changes: 7 additions & 0 deletions Runtime/PushNotificationsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

namespace Unity.Services.PushNotifications
{
/// <summary>
/// The main entry point for the Push Notifications SDK
/// </summary>
public static class PushNotificationsService
{
internal static PushNotificationsServiceInstance internalInstance;

/// <summary>
/// Returns the instance of the Push Notifications SDK
/// </summary>
/// <exception cref="Exception">Thrown when the SDK hasn't been initialised</exception>
public static IPushNotificationsService Instance
{
get
Expand Down
3 changes: 3 additions & 0 deletions Runtime/PushNotificationsServiceInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ internal class PushNotificationsServiceInstance : IPushNotificationsService, IPu
readonly ISystemWrapper m_PlatformWrapper;
readonly IMainThreadHelper m_MainThreadHelper;

/// <summary>
/// This is no longer required. Notification events are recorded for you automatically when you register for push notifications using RegisterForPushNotificationsAsync.
/// </summary>
[Obsolete("Do not use this. It will be deleted in a future version. Notification events are recorded for you automatically.")]
public IPushNotificationsAnalytics Analytics { get { return new PushNotificationsAnalyticsStub(m_Analytics); } }

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.unity.services.push-notifications",
"displayName": "Push Notifications",
"version": "4.0.0",
"version": "4.0.1",
"unity": "2021.3",
"_upm": {
"gameService": {
Expand All @@ -14,7 +14,7 @@
"Android",
"iOS"
],
"changelog": "### Changed\n\n- Bumps the unity version to 2021.3\n- Updated `com.unity.services.analytics` dependency to 6.0.1"
"changelog": "### Changed\n- Bug fix associated with the `registerForPushNotificationsAsync` method hanging for Android devices in some cases."
},
"description": "This package adds support for Push Notifications to your game. It allows sending rich push notifications with images, and provides analytics on the number of received push notifications.",
"dependencies": {
Expand All @@ -30,15 +30,15 @@
}
],
"relatedPackages": {
"com.unity.services.push-notifications.tests": "4.0.0"
"com.unity.services.push-notifications.tests": "4.0.1"
},
"upmCi": {
"footprint": "af8df0834b2b91b5e123cc826be53e8020d8f3d6"
"footprint": "c37f049cf68483ae743a4782992c45f60c5441d3"
},
"documentationUrl": "https://docs.unity3d.com/Packages/[email protected]/manual/index.html",
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/operate-services-sdk.git",
"type": "git",
"revision": "50b23cb45b26b142133375a4d22e504fd2707203"
"revision": "7d105ba1603a3370df040d31623257840cb44525"
}
}

0 comments on commit 50dc48a

Please sign in to comment.