OneSignal / OneSignal-iOS-SDK

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

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

Closed YurchukV closed 2 months ago

YurchukV commented 5 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?

iOS Version 15-18
OneSignal Version 5.2.1

AppDelegate -> didFinishLaunchingWithOptions

 OneSignal.initialize(Resources.OneSignalID, withLaunchOptions: launchOptions)
 OneSignal.Notifications.requestPermission { accepted in
   print("User accepted notifications: \(accepted)")
   print(OneSignal.User.pushSubscription.id)
 }

What did you expect to happen?

Easily access subs id

OneSignal iOS SDK version

5.2.1

iOS version

17, 16, 15

Specific iOS version

No response

Relevant log output

No response

Code of Conduct

nan-li commented 4 months ago

Hi @YurchukV thanks for reaching out with your question. If you are getting OneSignal.User.pushSubscription.id too early on a new app install, it will be null until the subscription ID is receieved from the OneSignal servers.

You can use the Push Subscription Observer to be notified of changes to the push subscription, including when the ID is received.