Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hackinghieser opened this issue Nov 7, 2019 · 2 comments

Comments

@hackinghieser
Copy link

Hi guys,

I have a problem with iOS/iPadOS > 13.0:

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.

Seems like there is now a size limit for the data you can store inside the NSUserDefaults, but there was nothing mentioned in the release notes, as far as I know....

Does anyone has the same problem? Is there a solution for this? Once you opened a file which is too big, it breaks the share extension and you have to restart the application to get it work again with smaller files.

My Application needs to import some files > 5mb, otherwise it cannot really be used anymore...

@bytronaviation
Copy link

@AlexanderHieser Did you manage to find a fix / workaround for this issue? We are experiencing the same issue

@hackinghieser
Copy link
Author

Hi @bytronaviation

I managed to create a little workaround, instead of storing the data in the UserDefaults I store the file temporarily in the shared folder between the app and the share extension, this resolved the issue for me.

// Get path for the shared container ( folder )
NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier: SHAREEXT_GROUP_IDENTIFIER];
NSLog([groupURL path]);
// Add filename to path
NSString *filePath = [[groupURL path] stringByAppendingPathComponent:filename ];
NSError *err;
// write File to the shared folder
BOOL ok = [data writeToFile:filePath options:NSDataWritingFileProtectionComplete error: &err];

And I retrieve it in the plugin:

NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier: SHAREEXT_GROUP_IDENTIFIER];
NSLog([groupURL path]);
 // Add filename to path
NSString *filePath = [[groupURL path] stringByAppendingPathComponent: filename ];
 NSError *err;
// write File to the shared folder
 NSData *data = [NSData dataWithContentsOfFile:filePath];
 NSArray* files = [self listFileAtPath:groupURL];
[[NSFileManager defaultManager] removeItemAtPath:filePath error:&err];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants