iOS 13 - Attempting to store >= 4194304 bytes of data in CFPreferences/NSUserDefaults on this platform is invalid

I'm trying to store a 2 separated Strings (73067 bytes) and (280628 bytes) to User Defaults, in older iOS versions just work fine, but in iOS 13, i can't save this data.



This is how i save the data:


UserDefaults.standard.set(myData1, forKey: KEY_MY_DATA_1)

UserDefaults.standard.synchronize()



UserDefaults.standard.set(myData2, forKey: KEY_MY_DATA_2)

UserDefaults.standard.synchronize()



Throws this error on iOS 13:


2019-08-19 15:34:24.616570+0200 myAppName[4108:240228] [User Defaults] CFPrefsPlistSource<0x6000037cc980> (Domain: com.domain.myAppName, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): Attempting to store >= 4194304 bytes of data in CFPreferences/NSUserDefaults on this platform is invalid. This is a bug in myAppName or a library it uses.

Encountered after attempting only 1 MB on watchOS 7, which is very unexpected, considering the docs state the only size limit is on tvOS:

Currently, there is only a size limit for data stored to local user defaults on tvOS, which posts a warning notification when user defaults storage reaches 512kB in size, and terminates apps when user defaults storage reaches 1MB in size.  https://developer.apple.com/documentation/foundation/userdefaults/1617187-sizelimitexceedednotification

This does not seem to be data about the value being stored but rather the number of keys being stored where the total must not exceed its limit.

Hi from 2023, problem still exist , iOS 17.1

iOS 13 - Attempting to store &gt;= 4194304 bytes of data in CFPreferences/NSUserDefaults on this platform is invalid
 
 
Q