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.

Hello @VincenDev. I actually have the samed bug on watchOS 6 with this message, when trying to store approximately 5mb of data :


Attempting to store >= 1048576 bytes of data in CFPreferences/NSUserDefaults on this platform is invalid. This is a bug in WatchApp Extension or a library it uses


On the other hand, I have no problem storing the same data in UserDefaults on iOS 13.

So ... what do we have to do? Is it a confirmed bug? Will it be fixed in next betas?

Problem persist in iOS 13 Beta 6

Same issue on iOS 13.1 Beta. Any resolution? Any reason for this issue? Is the amount of data that can be stored in NSUserDefaulsts limited in iOS 13? The documentation does not list any API changes related to this.

I'm having the same problem. Unable to share image files to main app due to this constrain. Anyone knows if this will be fixed or if it is intentional?

Hello every one,


I have exactly the same issue on iOS 13.1.3. Did you find any solution ?


Best regards,

This problem persist in iPadOS 13.2

Could the issue possibly be the use of

synchronize

? According to the docs we are not supposed to use it anymore. It isn't officially deprecated, but it is not supposed to be used.

I don't think so. I don't use "synchronize" and I got this error.

For me, it's when I try to store data >= 4mo in my UserDefaults group (ShareExtension <=> Host app).

Does anyone have any news on this? I'm still seeing the problem occur on WatchOS 6.1.

we are also seeing this on macOS (Catalina) now, but tests have revealed that despite this message the actual saving and reading of the preferences still works fine. we've tested up to one million keys with a combined size of 30 MB. many error messages but the actual operations worked just fine.


Apple, whats the plan here?

[User Defaults] CFPrefsPlistSource<0x600000609200> (Domain: ***, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): Attempting to store >= 1048576 bytes of data in CFPreferences/NSUserDefaults on this platform is invalid. This is a bug in Target or a library it uses


TvOS Simulator 4K, 13+

Found the UserDefaults limit in TvOS is 500Kb https://developer.apple.com/library/archive/documentation/General/Conceptual/AppleTV_PG/index.html. Also tried the UserDefaults.sizeLimitExceededNotification to clear all with


if let appDomain = Bundle.main.bundleIdentifier {

UserDefaults.standard.removePersistentDomain(forName: appDomain)

}

Any updates on this? I am still seeing this.

Bumping this iOS14.4 Xcode 12.4 still seeing this. Not able to save large data set.

Hi all, just wanted to add that I don't think this is a bug as UserDefaults was not built to house large data sets I believe. But only for small data sets accessed frequently.

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