react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[question]: Is it possible to change the AppId dinamically?

Open marcofuentes05 opened this issue 1 year ago • 3 comments

How can we help?

Context

So our app can work in one of multiple environments (dev/staging/prod/clientA/...). We have a OneSignal app for each instance, but the app is distributed as a single bundle downloadable from app stores. The users of each instance can download it and use a deep link to switch their "server" dinamically.

Currently, we react to the deep link by:

  1. opting out of push notifications (OneSignal.User.pushSubscription.optOut())
  2. logging out of current user (OneSignal.logout())
  3. setting the new app id in a persistent storage
  4. exiting the app (BackHandler.exitApp())

When the user opens the app again, the initialize method is called with the stored app id (it falls back to the default project, so its never null)

The problem

When a user switches from OneSignalApp1 to OneSignalApp2 (notifications work as expected with OneSignalApp1), a new subscription is created in OneSignalApp2 (we validate that by querying the user ID on the app dashboard), but the subscription status is set to No push token.

Questions

  1. What does this mean?
  2. What are we doing wrong?
  3. Is there an official way to achieve what we are trying?

We've search the docs but with no luck 😞

Image

Implementation details

react-native v0.75.5 react-native-onesignal 5.2.9 this is happening on both ios and android

Code of Conduct

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

marcofuentes05 avatar Mar 26 '25 19:03 marcofuentes05

Hi, thanks for reaching out. Changing app IDs dynamically is not supported. Each app installation should be used for a single OneSIgnal App ID.

nan-li avatar May 07 '25 19:05 nan-li

Thank you @nan-li for your answer!

Got it, is there any supported way we can keep our envs appart? Or are we forced to use the same OneSignal App for all of them? 🤔

marcofuentes05 avatar May 07 '25 20:05 marcofuentes05

I don't think so for your usage. A single app installation should maintain the same App ID. You can wipe the app data and it will start on a clean slate, or a new app installation.

nan-li avatar May 30 '25 21:05 nan-li