OneSignal-Unity-SDK icon indicating copy to clipboard operation
OneSignal-Unity-SDK copied to clipboard

[Fix]Multiple OneSignal instance

Open shepherd-l opened this issue 1 year ago • 0 comments

Description

One Line Summary

Fixes additional instance of OneSignalAndroid or OneSignaliOS from being created when calling OneSignal methods in Awake().

Details

Motivation

Removes logged error "Additional instance of OneSignalAndroid/OneSignaliOS created." Reproducible when calling OneSignal.Debug.LogLevel = LogLevel.Verbose; in Awake().

Scope

OneSignal.Default now manages the platform instance entirely instead of setting it again in platform initialization. Since OneSignal.Default already creates the platform instance in _getDefaultInstance(), we can remove the setter and the internal classes that used it: OneSignalAndroidInit, OneSignaliOSInit, OneSignalNativeInit.

Testing

Manual testing

Tested calling OneSignal debug and initialization methods in Awake(), app build with Unity 2022.3.10f1 of the OneSignal example app on a emulated Pixel 4 with Android 12 and a physical iPhone 12 with iOS 17.5.1.

Affected code checklist

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

Checklist

Overview

  • [x] I have filled out all REQUIRED sections above
  • [x] 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
  • [x] Any Public API changes are explained in the PR details and conform to existing APIs

Testing

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

Final pass

  • [x] 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.
  • [x] 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

shepherd-l avatar Jul 01 '24 15:07 shepherd-l