Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/error removing handlers when SDK is not initialized #1639

Conversation

Ribas187
Copy link
Contributor

@Ribas187 Ribas187 commented Jan 31, 2024

Description

Fix for the "initWithContext" error while trying to remove handlers when the SDK is not initialized

Details

Motivation

This issue happens in Android specifically when the app is closed and the OneSignal SDK has not been initialized yet
The error accused in the log is this one "Must call 'initWithContext' before use", and can be seen in the opened issue [Bug]: initWithContext error in android-1554

Scope

The mentioned code is inside the removeHandlers() method which is called inside onHostDestroy() and onCatalystInstanceDestroy() and causes a crash when the SDK has not been initialized before.
This PR adds one verification to check whether the initialization is made with the value oneSignalInitDone

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Signed-off-by: Guilherme Ribas <guilherme.ribas.tech@gmail.com>
@Ribas187 Ribas187 changed the base branch from rel/5.0.5 to major_release_5.0.0 January 31, 2024 15:44
Copy link
Contributor Author

@Ribas187 Ribas187 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Ribas187)

@jpangan
Copy link

jpangan commented Feb 11, 2024

Hello guys. What's the status of this? it seems like everyone is facing the same issue.

@Ribas187
Copy link
Contributor Author

Ribas187 commented Feb 12, 2024

Hello guys. What's the status of this? it seems like everyone is facing the same issue.

Hey @jpangan I need approval from @nan-li or @jennantilla on this one. I faced the same issue in my company, but while we wait for the new version, we did a workaround by applying this change using a patch in the node_module package

@nan-li
Copy link
Contributor

nan-li commented Feb 12, 2024

Thank you @Ribas187 for submitting and testing this PR!

@jennantilla jennantilla merged commit a24559b into OneSignal:major_release_5.0.0 Feb 13, 2024
3 checks passed
@jennantilla jennantilla mentioned this pull request Feb 13, 2024
Copy link

@Romick2005 Romick2005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants