Skip to content

[Bug]: Duplicate subscription after closing and opening the app again #2110

Description

@qidulak

What happened?

Not sure, if this is bug, but when I start freshly installed ap on device and log user in, it will properly create subscription. But when I kill the app and start again, I see in one signal dashboard duplicated subsription, for different OneSignalID and with sstatus not PermissionNotGranted. This subscription is also without external Id filled.

image

After another app kill and start nothing change and this subscription just hang in the dashboard. I can normally send Push notifications to user 28509928-339b-acb7-e601-84f616f2e0e0.

Did not noticed this behavior for iOS devices/simulators

this is how I init/login user

  oneSignalInit(appId: string): Observable<boolean> {
    // Uncomment to set OneSignal device logging
    // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose
    OneSignal.Debug.setLogLevel(6);
    OneSignal.Debug.setAlertLevel(0);

    OneSignal.initialize(appId);

    OneSignal.Notifications.removeEventListener('click', this.clickHandler);
    OneSignal.Notifications.addEventListener('click', this.clickHandler);

    OneSignal.Notifications.removeEventListener(
      'foregroundWillDisplay',
      this.foregroundDisplayHandler,
    );

    OneSignal.Notifications.addEventListener(
      'foregroundWillDisplay',
      this.foregroundDisplayHandler,
    );


    return from(OneSignal.Notifications.getPermissionAsync()).pipe(
      switchMap((hasPermission) => {
        if (hasPermission) {
          return of(true);
        } else {
          return from(OneSignal.Notifications.requestPermission(true));
        }
      }),
    );
  }
  
  userChangedListener = (event: UserChangedState) => {
    if (event.current.onesignalId) {
      OneSignal.User.pushSubscription.optIn();
      this.notificationIdSubject.next(event.current.onesignalId);
    }
  };

  // When login, we collect oneSignal ID for user
  login(userName: string): Observable<string> {
    OneSignal.User.addEventListener('change', this.userChangedListener);
    OneSignal.login(userName);

    return from(OneSignal.User.pushSubscription.getIdAsync()).pipe(
      switchMap(() => this.notificationIdSubject.asObservable()),
    );
}

Steps to reproduce?

1. Launch the app and let perorm init and login 
2. Kill The app
3. Launch the app again

What did you expect to happen?

I suppose there not should be another subscription

OneSignal Android SDK version

5.1.13

Android version

12

Specific Android models

* Huavei P30 Pro 
* Android emulator Pixel 4 Api 33

Relevant log output

No response

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions