From 4cdf3fe0e00daa6409411ffcda198219246c673e Mon Sep 17 00:00:00 2001 From: Shepherd Date: Tue, 26 Sep 2023 14:02:30 -0400 Subject: [PATCH 1/6] Update OneSignal iOS SDK to 5.0.2 --- OneSignalExample/Assets/OneSignal/CHANGELOG.md | 1 + com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/OneSignalExample/Assets/OneSignal/CHANGELOG.md b/OneSignalExample/Assets/OneSignal/CHANGELOG.md index e771bfc5e..b727b58e6 100644 --- a/OneSignalExample/Assets/OneSignal/CHANGELOG.md +++ b/OneSignalExample/Assets/OneSignal/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `InstallEdm4uStep` now imports version [1.2.177](https://github.com/googlesamples/unity-jar-resolver/releases/tag/v1.2.177) of [EDM4U](https://github.com/googlesamples/unity-jar-resolver) - Updated included Android SDK to [5.0.1](https://github.com/OneSignal/OneSignal-Android-SDK/releases/tag/5.0.1) +- Updated included iOS SDK to [5.0.2](https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/5.0.2) ### Fixed - Sending VSAttribution data from the editor diff --git a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml index 55ebd260e..1fe24b71d 100644 --- a/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml +++ b/com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml @@ -1,5 +1,5 @@  - + \ No newline at end of file From 88f96dc28dd7cda996c39131da0814b772cfa9de Mon Sep 17 00:00:00 2001 From: Shepherd Date: Tue, 26 Sep 2023 14:12:26 -0400 Subject: [PATCH 2/6] Fire notifications clicked event when app is opened from click on iOS --- .../iOS/OneSignalUnityBridgeNotifications.mm | 3 +- .../iOS/UIApplication+OneSignalUnity.mm | 2 +- .../Runtime/iOSNotificationsManager.cs | 33 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm b/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm index 205182e51..030cdc34b 100644 --- a/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm +++ b/com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm @@ -70,7 +70,6 @@ - (instancetype) init { if (self = [super init]) { [OneSignal.Notifications addPermissionObserver:self]; [OneSignal.Notifications addForegroundLifecycleListener:self]; - [OneSignal.Notifications addClickListener:self]; _willDisplayEvents = [NSMutableDictionary new]; } @@ -161,5 +160,7 @@ void _notificationsDisplay(const char* notifcationId) { void _notificationsSetClickCallback(ClickListenerDelegate callback) { [[OneSignalNotificationsObserver sharedNotificationsObserver] setClickDelegate:callback]; + + [OneSignal.Notifications addClickListener:[OneSignalNotificationsObserver sharedNotificationsObserver]]; } } \ No newline at end of file diff --git a/com.onesignal.unity.ios/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm b/com.onesignal.unity.ios/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm index 09031a521..7fde541b0 100644 --- a/com.onesignal.unity.ios/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm +++ b/com.onesignal.unity.ios/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm @@ -97,7 +97,7 @@ - (void)setOneSignalUnityDelegate:(id )delegate { - (BOOL)oneSignalApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [OneSignalWrapper setSdkType:@"unity"]; [OneSignalWrapper setSdkVersion:@"050002"]; - [OneSignal setLaunchOptions:launchOptions]; + [OneSignal initialize:nil withLaunchOptions:launchOptions]; if ([self respondsToSelector:@selector(oneSignalApplication:didFinishLaunchingWithOptions:)]) return [self oneSignalApplication:application didFinishLaunchingWithOptions:launchOptions]; diff --git a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs index 1b96c9bd2..ede239928 100644 --- a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs +++ b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs @@ -54,9 +54,22 @@ internal sealed class iOSNotificationsManager : INotificationsManager { private delegate void BooleanResponseDelegate(int hashCode, bool response); public event EventHandler ForegroundWillDisplay; - public event EventHandler Clicked; public event EventHandler PermissionChanged; + private bool _clickDelegate; + private EventHandler _clicked; + public event EventHandler Clicked { + add { + // only add one click listener + if (!_clickDelegate) { + _clicked += value; + _clickDelegate = true; + _notificationsSetClickCallback(_onClicked); + } + } + remove { _clicked -= value; } + } + private static iOSNotificationsManager _instance; public iOSNotificationsManager() { @@ -88,7 +101,6 @@ public void ClearAllNotifications() { public void Initialize() { _notificationsAddPermissionObserver(_onPermissionStateChanged); _notificationsSetForegroundWillDisplayCallback(_onForegroundWillDisplay); - _notificationsSetClickCallback(_onClicked); } [AOT.MonoPInvokeCallback(typeof(PermissionListenerDelegate))] @@ -133,23 +145,10 @@ private static void _onClicked(string notification, string resultActionId, strin _fillNotifFromObj(ref notif, Json.Deserialize(notification)); var result = new NotificationClickResult(resultActionId, resultUrl); - NotificationClickEventArgs args = new NotificationClickEventArgs(notif, result); - EventHandler handler = _instance.Clicked; - if (handler != null) - { - if (OneSignalPlatform.DidInitialize) - UnityMainThreadDispatch.Post(state => handler(_instance, args)); - else { - void invokeOpened(string appId) { - OneSignalPlatform.OnInitialize -= invokeOpened; - UnityMainThreadDispatch.Post(state => handler(_instance, args)); - } - - OneSignalPlatform.OnInitialize += invokeOpened; - } - } + EventHandler handler = _instance._clicked; + UnityMainThreadDispatch.Post(state => handler(_instance, args)); } private static void _fillNotifFromObj(ref iOSDisplayableNotification notif, object notifObj) { From fe140f2c6fb7a6f6209569598be85ab15feb8f82 Mon Sep 17 00:00:00 2001 From: Shepherd Date: Tue, 26 Sep 2023 14:12:59 -0400 Subject: [PATCH 3/6] Change listener delegate to private --- com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs index ede239928..879b4eff2 100644 --- a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs +++ b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs @@ -48,7 +48,7 @@ internal sealed class iOSNotificationsManager : INotificationsManager { [DllImport("__Internal")] private static extern void _notificationsWillDisplayEventPreventDefault(string notificationId); [DllImport("__Internal")] private static extern void _notificationsSetClickCallback(ClickListenerDelegate callback); - public delegate void PermissionListenerDelegate(bool permission); + private delegate void PermissionListenerDelegate(bool permission); private delegate void WillDisplayListenerDelegate(string notification); private delegate void ClickListenerDelegate(string notification, string resultActionId, string resultUrl); private delegate void BooleanResponseDelegate(int hashCode, bool response); From cfc40ed2fc99f94d075348e70401fc2fc53951c4 Mon Sep 17 00:00:00 2001 From: Shepherd Date: Tue, 26 Sep 2023 14:13:18 -0400 Subject: [PATCH 4/6] Update CHANGELOG --- OneSignalExample/Assets/OneSignal/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/OneSignalExample/Assets/OneSignal/CHANGELOG.md b/OneSignalExample/Assets/OneSignal/CHANGELOG.md index b727b58e6..2962b6041 100644 --- a/OneSignalExample/Assets/OneSignal/CHANGELOG.md +++ b/OneSignalExample/Assets/OneSignal/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated included iOS SDK to [5.0.2](https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/5.0.2) ### Fixed - Sending VSAttribution data from the editor +- iOS notifications clicked event to fire when app is opened from clicking on a notification ## [5.0.2] ### Fixed From 4a88a62391d55b81eba274e9cbd45b32cbba97e0 Mon Sep 17 00:00:00 2001 From: Shepherd Date: Tue, 26 Sep 2023 18:58:28 -0400 Subject: [PATCH 5/6] Allow multiple click listeners --- .../Runtime/iOSNotificationsManager.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs index 879b4eff2..cab61bc65 100644 --- a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs +++ b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs @@ -56,14 +56,16 @@ internal sealed class iOSNotificationsManager : INotificationsManager { public event EventHandler ForegroundWillDisplay; public event EventHandler PermissionChanged; - private bool _clickDelegate; + // Only set the native listner once + private bool _clickNativeListenerSet; + private EventHandler _clicked; public event EventHandler Clicked { add { - // only add one click listener - if (!_clickDelegate) { - _clicked += value; - _clickDelegate = true; + _clicked += value; + + if (!_clickNativeListenerSet) { + _clickNativeListenerSet = true; _notificationsSetClickCallback(_onClicked); } } From b5a4a06712f10e658795a442fe2388de7969697e Mon Sep 17 00:00:00 2001 From: Shepherd Date: Tue, 26 Sep 2023 18:58:39 -0400 Subject: [PATCH 6/6] Update CHANGELOG --- OneSignalExample/Assets/OneSignal/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneSignalExample/Assets/OneSignal/CHANGELOG.md b/OneSignalExample/Assets/OneSignal/CHANGELOG.md index 2962b6041..7087e93cf 100644 --- a/OneSignalExample/Assets/OneSignal/CHANGELOG.md +++ b/OneSignalExample/Assets/OneSignal/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated included iOS SDK to [5.0.2](https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/5.0.2) ### Fixed - Sending VSAttribution data from the editor -- iOS notifications clicked event to fire when app is opened from clicking on a notification +- iOS notifications clicked event firing if the app was cold started from clicking a notification ## [5.0.2] ### Fixed