@@ -211,15 +211,23 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
211211 sessionModel = services.getService<SessionModelStore >().model
212212 operationRepo = services.getService<IOperationRepo >()
213213
214- // initWithContext is called by our internal services/receivers/activites but they do not provide
214+ var forceCreateUser = false
215+
216+ // initWithContext is called by our internal services/receivers/activities but they do not provide
215217 // an appId (they don't know it). If the app has never called the external initWithContext
216218 // prior to our services/receivers/activities we will blow up, as no appId has been established.
217219 if (appId == null && ! configModel!! .hasProperty(ConfigModel ::appId.name)) {
218- Logging .warn(" initWithContext called without providing appId, and no appId has been established!" )
219- return false
220+ val legacyAppId = getLegacyAppId()
221+ if (legacyAppId == null ) {
222+ Logging .warn(" initWithContext called without providing appId, and no appId has been established!" )
223+ return false
224+ } else {
225+ Logging .debug(" initWithContext: using cached legacy appId $legacyAppId " )
226+ forceCreateUser = true
227+ configModel!! .appId = legacyAppId
228+ }
220229 }
221230
222- var forceCreateUser = false
223231 // if the app id was specified as input, update the config model with it
224232 if (appId != null ) {
225233 if (! configModel!! .hasProperty(ConfigModel ::appId.name) || configModel!! .appId != appId) {
@@ -418,6 +426,16 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
418426 }
419427 }
420428
429+ /* *
430+ * Returns the cached app ID from v4 of the SDK, if available.
431+ */
432+ private fun getLegacyAppId (): String? {
433+ return preferencesService.getString(
434+ PreferenceStores .ONESIGNAL ,
435+ PreferenceOneSignalKeys .PREFS_LEGACY_APP_ID ,
436+ )
437+ }
438+
421439 private fun createAndSwitchToNewUser (
422440 suppressBackendOperation : Boolean = false,
423441 modify : (
0 commit comments