@@ -211,15 +211,23 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
211
211
sessionModel = services.getService<SessionModelStore >().model
212
212
operationRepo = services.getService<IOperationRepo >()
213
213
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
215
217
// an appId (they don't know it). If the app has never called the external initWithContext
216
218
// prior to our services/receivers/activities we will blow up, as no appId has been established.
217
219
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
+ }
220
229
}
221
230
222
- var forceCreateUser = false
223
231
// if the app id was specified as input, update the config model with it
224
232
if (appId != null ) {
225
233
if (! configModel!! .hasProperty(ConfigModel ::appId.name) || configModel!! .appId != appId) {
@@ -418,6 +426,16 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
418
426
}
419
427
}
420
428
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
+
421
439
private fun createAndSwitchToNewUser (
422
440
suppressBackendOperation : Boolean = false,
423
441
modify : (
0 commit comments