Pushwoosh/pushwoosh-unity

Support for clearLaunchNotification

Closed this issue · 5 comments

Hi!,

I'm currently trying to determine whether a Unity App is opened from a Push/Local Notification or not. So far, in Android, checking for a non-null value from GetLaunchNotification when the Application resumes, seems to partially do the job. But, I can't find any way to delete this reference, so after relaunching the application from the icon or in any other way, it still appears as it was opened from the Notification.

I noticed that some time ago you introduced the method ClearLaunchNotification in the Android SDK to sort out this issue. Could you also include it into the Unity's plugin?

Also, what would be an alternative for iOS to replicate this behaviour?

Thanks in advance for any help!

GetLaunchNotification and ClearLaunchNotification are now available on both iOS and Android.

I've tested on both platforms and it works as expected. Thanks very much for your promptness.

Reopening after noticing a catch in iOS. Using your demo App, it all works fine, detecting the Launch Notification every time and displaying its contents in the Text component; all good until ClearLaunchNotification is called.

Because I need to fetch the Launch Notification content every time the application is launched, even if in the background, I moved the logic that gets the notification to the OnApplicationPause method, like this:

private void OnApplicationPause(bool paused)
    {
        if (!paused && isRegistered)
        {
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)

            Pushwoosh.Instance.SetUserId("%userId%");

            Dictionary<string, object> attributes = new Dictionary<string, object>()
            {
                { "attribute", "value" },
            };

            Pushwoosh.Instance.PostEvent("applicationOpened", attributes);

            AndroidSpecific.SetActive (true);
            string launchNotification = Pushwoosh.Instance.GetLaunchNotification();
            if (launchNotification == null)
                launchNotificationString = "No launch notification";
            else
            {
                launchNotificationString = launchNotification;
            }

            Pushwoosh.Instance.ClearLaunchNotification();
#endif
        }
    }

If I comment out the line that clears the launch notification, it all goes fine. Having it makes the App read and display correctly the first launch Notification, but none more afterwards. I tried to fix it by using OnApplicationPause as a coroutine and giving some time before the clearing is executed to no avail.

Any thoughts?

Couldn't reproduce the same issue in Android. It'll retrieve correctly the Launch notification (if any), even after being cleaned every time the application is resumed.

Tested the latest functionality on iOS and seems to work very well now. Thanks very much!