@@ -154,9 +154,20 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
154154 startObservingAppleIDCredentialRevoked ( )
155155
156156 NotificationCenter . default. post ( name: . applicationLaunchCompleted, object: nil )
157+
158+ copyToSharedDefaultsIfNeeded ( )
157159 return true
158160 }
159161
162+ private func copyToSharedDefaultsIfNeeded( ) {
163+ if !AppConfiguration. isJetpack && FeatureFlag . sharedUserDefaults. enabled && !UserDefaults. standard. isOneOffMigrationComplete {
164+ let dict = UserDefaults . standard. dictionaryRepresentation ( )
165+ for (key, value) in dict {
166+ UserPersistentStore . standard. set ( value, forKey: key)
167+ UserDefaults . standard. isOneOffMigrationComplete = true
168+ }
169+ }
170+ }
160171
161172 func applicationWillTerminate( _ application: UIApplication ) {
162173 DDLogInfo ( " \( self ) \( #function) " )
@@ -512,7 +523,7 @@ extension WordPressAppDelegate {
512523 }
513524
514525 @objc func configureWordPressComApi( ) {
515- if let baseUrl = UserDefaults . standard . string ( forKey: " wpcom-api-base-url " ) {
526+ if let baseUrl = UserPersistentStoreFactory . instance ( ) . string ( forKey: " wpcom-api-base-url " ) {
516527 Environment . replaceEnvironment ( wordPressComApiBase: baseUrl)
517528 }
518529 }
@@ -646,9 +657,9 @@ extension WordPressAppDelegate {
646657 let unknown = " Unknown "
647658
648659 let device = UIDevice . current
649- let crashCount = UserDefaults . standard . integer ( forKey: " crashCount " )
660+ let crashCount = UserPersistentStoreFactory . instance ( ) . integer ( forKey: " crashCount " )
650661
651- let extraDebug = UserDefaults . standard . bool ( forKey: " extra_debug " )
662+ let extraDebug = UserPersistentStoreFactory . instance ( ) . bool ( forKey: " extra_debug " )
652663
653664 let bundle = Bundle . main
654665 let detailedVersionNumber = bundle. detailedVersionNumber ( ) ?? unknown
@@ -668,7 +679,7 @@ extension WordPressAppDelegate {
668679
669680 let devicePlatform = UIDeviceHardware . platformString ( )
670681 let architecture = UIDeviceHardware . platform ( )
671- let languages = UserDefaults . standard . array ( forKey: " AppleLanguages " )
682+ let languages = UserPersistentStoreFactory . instance ( ) . array ( forKey: " AppleLanguages " )
672683 let currentLanguage = languages? . first ?? unknown
673684 let udid = device. wordPressIdentifier ( ) ?? unknown
674685
@@ -687,25 +698,25 @@ extension WordPressAppDelegate {
687698 if !AccountHelper. isLoggedIn {
688699 // When there are no blogs in the app the settings screen is unavailable.
689700 // In this case, enable extra_debugging by default to help troubleshoot any issues.
690- guard UserDefaults . standard . object ( forKey: " orig_extra_debug " ) == nil else {
701+ guard UserPersistentStoreFactory . instance ( ) . object ( forKey: " orig_extra_debug " ) == nil else {
691702 // Already saved. Don't save again or we could loose the original value.
692703 return
693704 }
694705
695- let origExtraDebug = UserDefaults . standard . bool ( forKey: " extra_debug " ) ? " YES " : " NO "
696- UserDefaults . standard . set ( origExtraDebug, forKey: " orig_extra_debug " )
697- UserDefaults . standard . set ( true , forKey: " extra_debug " )
706+ let origExtraDebug = UserPersistentStoreFactory . instance ( ) . bool ( forKey: " extra_debug " ) ? " YES " : " NO "
707+ UserPersistentStoreFactory . instance ( ) . set ( origExtraDebug, forKey: " orig_extra_debug " )
708+ UserPersistentStoreFactory . instance ( ) . set ( true , forKey: " extra_debug " )
698709 WordPressAppDelegate . setLogLevel ( . verbose)
699710 } else {
700- guard let origExtraDebug = UserDefaults . standard . string ( forKey: " orig_extra_debug " ) else {
711+ guard let origExtraDebug = UserPersistentStoreFactory . instance ( ) . string ( forKey: " orig_extra_debug " ) else {
701712 return
702713 }
703714
704715 let origExtraDebugValue = ( origExtraDebug as NSString ) . boolValue
705716
706717 // Restore the original setting and remove orig_extra_debug
707- UserDefaults . standard . set ( origExtraDebugValue, forKey: " extra_debug " )
708- UserDefaults . standard . removeObject ( forKey: " orig_extra_debug " )
718+ UserPersistentStoreFactory . instance ( ) . set ( origExtraDebugValue, forKey: " extra_debug " )
719+ UserPersistentStoreFactory . instance ( ) . removeObject ( forKey: " orig_extra_debug " )
709720
710721 if origExtraDebugValue {
711722 WordPressAppDelegate . setLogLevel ( . verbose)
0 commit comments