OneSignal / OneSignal-Flutter-SDK

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

[Bug]: OneSignal.User.pushSubscription.id is null! #766

Open aydemiromer opened 8 months ago

aydemiromer commented 8 months ago

What happened?

I can't access subscriptionId , I want to use rest api in my app but I need subscriptionId for specific notification. I tried with copy subs id one signal panel thats runned not have a problem in my code, but inside the code not access have a directly subs id.

Steps to reproduce?

This is my code => 

 OneSignal.initialize(Env.oneSignal);
    OneSignal.login(token ?? '');
    var sendTags = {
      'deviceLanguage': deviceLang,
      'deviceCountry': deviceCountry,
      'status': 'free'
    };
    OneSignal.User.addTags(sendTags);

    print(OneSignal.User.pushSubscription.id);

What did you expect to happen?

Easily access subs id

OneSignal Flutter SDK version

5.0.3

Which platform(s) are affected?

Relevant log output

No response

Code of Conduct

jackie-maxx commented 8 months ago

i have the same issued

emawby commented 8 months ago

@aydemiromer My guess is that the subscription id has not been received from the server at the time you are attempting to access it. My recommendation would be to use the push subscription observer to get notified when a property of the subscription has changed. This will notify your app when the id has been set

pimtidaN455 commented 6 months ago

I encountered this problem as well.

ashutosh9152 commented 3 months ago

I am on v5.1.2 and when I am calling OneSignal.User.pushSubscription.id. I am getting null but after some milliseconds I am getting the data. This same issue was on OneSignal-Cordova #918 you can check there. It is solved now but I am getting that issue in flutter.

Is there a possible solution for the future? I would be very grateful if anyone could help solve this problem.

YurchukV commented 2 weeks ago

i have the same issued SDK 5.2.1