j3k0 / cordova-plugin-openwith

Get your Cordova App in the O.S. "Share" menu on iOS and Android
MIT License
137 stars 114 forks source link

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

Open hackinghieser opened 4 years ago

hackinghieser commented 4 years ago

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 commented 4 years ago

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

hackinghieser commented 4 years ago

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];