OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

[Fix]Multiple OneSignal instance #741

Closed shepherd-l closed 4 months ago

shepherd-l commented 4 months ago

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

Checklist

Overview

Testing

Final pass


This change is Reviewable