Skip to content

[Bug]: getOptedInAsync returns false twice when toggling optIn/optOut #1161

@nunoarruda

Description

@nunoarruda

What happened?

getOptedInAsync returns false twice when toggling optIn/optOut on iOS. Works fine on Android.

Steps to reproduce?

1. Install onesignal-cordova-plugin on a Capacitor project
2. Create a toggle button
3. Add the code from below to the button
4. Tap the toggle button several times
5. Note that getOptedInAsync logs false twice in a row

Code:

pushAllowed = false;

async togglePush() {
    if (this.pushAllowed) {
      OneSignal.User.pushSubscription.optOut();
    } else {
      OneSignal.User.pushSubscription.optIn();
    }

    const optedIn = await OneSignal.User.pushSubscription.getOptedInAsync();
    console.log(`optedIn: ${optedIn}`);
    pushAllowed = optedIn;
  }

What did you expect to happen?

I expected getOptedInAsync log to toggle between true and false

OneSignal Cordova SDK version

5.3.1

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

optedIn: true
optedIn: false
optedIn: false
optedIn: true
optedIn: false
optedIn: false

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions