diff --git a/ios/app/brave_core_main.mm b/ios/app/brave_core_main.mm index 959623286be..80b2e18eb2e 100644 --- a/ios/app/brave_core_main.mm +++ b/ios/app/brave_core_main.mm @@ -212,8 +212,12 @@ const BraveCoreLogSeverity BraveCoreLogSeverityVerbose = - (void)onAppEnterBackground:(NSNotification*)notification { auto* context = GetApplicationContext(); - if (context) + if (context) { context->OnAppEnterBackground(); + // Since we don't use the WebViewWebMainParts, local state is never commited + // on app background + context->GetLocalState()->CommitPendingWrite(); + } } - (void)onAppEnterForeground:(NSNotification*)notification { @@ -223,6 +227,9 @@ const BraveCoreLogSeverity BraveCoreLogSeverityVerbose = } - (void)onAppWillTerminate:(NSNotification*)notification { + // ApplicationContextImpl doesn't get teardown call at the moment because we + // cannot dealloc this class yet without crashing. + GetApplicationContext()->GetLocalState()->CommitPendingWrite(); [[NSNotificationCenter defaultCenter] removeObserver:self]; } diff --git a/ios/browser/api/p3a/brave_p3a_utils.mm b/ios/browser/api/p3a/brave_p3a_utils.mm index 4d9b9c27b40..75d6abffd52 100644 --- a/ios/browser/api/p3a/brave_p3a_utils.mm +++ b/ios/browser/api/p3a/brave_p3a_utils.mm @@ -38,6 +38,7 @@ - (void)setIsP3AEnabled:(bool)isP3AEnabled { _localState->SetBoolean(brave::kP3AEnabled, isP3AEnabled); + _localState->CommitPendingWrite(); } - (bool)isNoticeAcknowledged { @@ -46,6 +47,7 @@ - (void)setIsNoticeAcknowledged:(bool)isNoticeAcknowledged { _localState->SetBoolean(brave::kP3ANoticeAcknowledged, isNoticeAcknowledged); + _localState->CommitPendingWrite(); } - (BraveHistogramsController*)histogramsController {