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 60 forks source link

[question]: Getting Error On Logout Call #715

Open G-r-i-n-c-h opened 3 months ago

G-r-i-n-c-h commented 3 months ago

How can we help?

Hey, Got some problem Calling logout and reciving something like that

Must call 'initWithContext' before 'logout' java.lang.Exception: Must call 'initWithContext' before 'logout' at com.onesignal.internal.OneSignalImp.logout(OneSignalImp.kt:423) at com.onesignal.OneSignal.logout(OneSignal.kt:193) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.-$$Nest$mnativeRender(Unknown Source:0) at com.unity3d.player.UnityPlayer$F$a.handleMessage(Unknown Source:122) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at com.unity3d.player.UnityPlayer$F.run(Unknown Source:24) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.AndroidJavaObject._CallStatic (System.IntPtr methodID, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0

does anyone have the same problem ?

Code of Conduct

shepherd-l commented 3 months ago

Thanks for sharing!

What version of the OneSignal Unity SDK and Unity Editor are you using?

Are you able to reproduce this error? And could you provide the steps to do so

Can you provide your entire log with verbose logging turned on by calling OneSignal.Debug.LogLevel = LogLevel.Verbose before initializing

G-r-i-n-c-h commented 3 months ago

So, Problem is that i am getting this really random. In my solution different user can login and logout.

Unity 2022.3.22f, Onesignal 5.1.1.

shepherd-l commented 3 months ago

Where are you calling OneSignal.Logout()? Could you provide steps to what you are doing in your code?

Are you calling OneSignal.Logout() before OneSignal.Initialize(appId)? OneSignal.Initialize(appId) should be called first on app startup because it initializes the OneSignal SDK.

G-r-i-n-c-h commented 3 months ago

When user logs in with his account i am calling OneSignal.Initialize(AppID); Then waiting for user response to set external user id with this OneSignal.Login(CurrentUserData.id); After that user can log out any time and log in again same flow is applied.

shepherd-l commented 3 months ago

Can a user be logged out without calling OneSignal.Initialize(appId) on a new cold start? OneSignal.Initialize needs to be called on every new cold start of the application before any methods should be used.

G-r-i-n-c-h commented 3 months ago

Got it. that was a case i was calling only once init and then only user login/logout. Will continue checking if all good will update here.