OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

[Bug]: PushSubscriptionStateChanged not run with userid #613

Open mskalash opened 1 year ago

mskalash commented 1 year ago

What happened?

after making the basic settings, the PushSubscriptionStateChanged method is called when the application is first launched, but does not pass the userid.

Steps to reproduce?

1. Install OneSignal
2. Add the line OneSignal.Default.Initialize(osconf.OneSignalKey);
3. Add the line OneSignal.Default.PushSubscriptionStateChanged += (current, previous) => {Debug.Log("Start User " + OneSignal.Default.PushSubscriptionState.userId); };

What did you expect to happen?

At the moment I have created a method that every 4 seconds calls the initialization of a new one and after 3 calls the system starts IEnumerator WaitOS() { yield return new WaitForSeconds(4); if (!notreload) { OneSignal.Default.Initialize(osconf.OneSignalKey); StartCoroutine(WaitOS()); } } example code how it works now

Unity version

2021.3.16 (latest)

OneSignal Unity SDK version

3.0.10

Platform

Android

Relevant log output

when displaying the full log, I see the following moment
2023/06/01 17:48:10.099 8687 8857 Info OneSignal Device registered, UserId = ххххххх
  UserId removed for security purposes
but PushSubscriptionStateChanged method is not called

Code of Conduct

shepherd-l commented 1 year ago

Thanks for reporting

Could you provide your entire log with verbose logging?
 You can add verbose logging by adding OneSignal.Default.LogLevel = LogLevel.Verbose; before OneSignal.Default.Initialize(appId); To narrow it the issue down, could you also call OneSignal.Default.Initialize in your code only once?

I tested your steps in a new project and added OneSignal.Default.Initialize and OneSignal.Default.PushSubscriptionStateChanged to Start()

void Start()
{
    OneSignal.Default.Initialize(appId);
    OneSignal.Default.PushSubscriptionStateChanged += (current, previous) => {Debug.Log("Start User " + OneSignal.Default.PushSubscriptionState.userId); };
}

I noticed that in my Android Studio logcat, Debug.Log("Start User " + OneSignal.Default.PushSubscriptionState.userId)shows up when I filter for “Unity” and not “OneSignal” - is this the case for you as well?