OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

getDeviceState is missing

Open berkaymazlumlar opened this issue 2 years ago • 5 comments
trafficstars

Can't use getDeviceState method with new version. I looked documentation but didn't see any information about this. What could I use instead?

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

berkaymazlumlar avatar Sep 13 '23 08:09 berkaymazlumlar

@berkaymazlumlar Hello what data from the device state are you looking for? You are able to use the permission and subscription observers to be updated when data on either of those objects change.

emawby avatar Sep 14 '23 17:09 emawby

OneSignal.shared.getDeviceState().then((deviceState) async {
    debugPrint("initOnesignalNormalPush DeviceState: ${deviceState?.jsonRepresentation()}");
    String? playerId = deviceState?.userId;
}

This is from older sdk version. I also look for function similar this to get playerid. Is that for new sdk:

OneSignal.User.pushSubscription.id if so, I got null value of id

harryhieunguyen avatar Sep 26 '23 01:09 harryhieunguyen

@harrynguyen2510 Thank you for reaching out OneSignal.User.pushSubscription.id should not always return nil so it sounds like either something is going wrong with registering your device or something is going wrong retrieving the value in the SDK. Is the device able to receive push (does it show up in the dashboard)? If not then it is likely an issue registering and if so then it is an issue retrieving the value

emawby avatar Oct 02 '23 17:10 emawby

Any update?

reynaldi18 avatar Feb 26 '24 06:02 reynaldi18

I also receiving null when i am calling. OneSignal.User.pushSubscription.id I am getting the value after some time. I also tried adding await but still it is not working .

This same issue was on OneSignal Cordova but there it is solved by deprecating OneSignal.User.pushSubscription.id and adding await OneSignal.User.pushSubscription.getIdAsync()

There issue number is #918.

ashutosh9152 avatar Mar 21 '24 07:03 ashutosh9152