diff --git a/OneSignalExample/Assets/OneSignal/CHANGELOG.md b/OneSignalExample/Assets/OneSignal/CHANGELOG.md index e771bfc5e..7087e93cf 100644 --- a/OneSignalExample/Assets/OneSignal/CHANGELOG.md +++ b/OneSignalExample/Assets/OneSignal/CHANGELOG.md @@ -8,8 +8,10 @@ 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 +- iOS notifications clicked event firing if the app was cold started from clicking a notification ## [5.0.2] ### Fixed 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 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..cab61bc65 100644 --- a/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs +++ b/com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs @@ -48,15 +48,30 @@ 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); public event EventHandler ForegroundWillDisplay; - public event EventHandler Clicked; public event EventHandler PermissionChanged; + // Only set the native listner once + private bool _clickNativeListenerSet; + + private EventHandler _clicked; + public event EventHandler Clicked { + add { + _clicked += value; + + if (!_clickNativeListenerSet) { + _clickNativeListenerSet = true; + _notificationsSetClickCallback(_onClicked); + } + } + remove { _clicked -= value; } + } + private static iOSNotificationsManager _instance; public iOSNotificationsManager() { @@ -88,7 +103,6 @@ public void ClearAllNotifications() { public void Initialize() { _notificationsAddPermissionObserver(_onPermissionStateChanged); _notificationsSetForegroundWillDisplayCallback(_onForegroundWillDisplay); - _notificationsSetClickCallback(_onClicked); } [AOT.MonoPInvokeCallback(typeof(PermissionListenerDelegate))] @@ -133,23 +147,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) {