Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data + CloudKit integration, large binary files sync crash

Core Data model attribute with type binary and "Allow External Storage" enabled cause crash in NSPersistentCloudKitContainer sync mechanism.

This happens only on receiving device, meaning upload to CloudKit is successful, but download from CloudKit causes crash when in NSManagedContext.

<NSSQLSaveChangesRequestContext: 0x281ec8420> , *** NSAllocateMemoryPages(28317598) failed with userInfo of (null)

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** NSAllocateMemoryPages(30318498) failed

This is obviously a memory crash, but I can't figure out how to workaround it, it seems to be an iOS bug.

like image 764
Alexandr Mazanov Avatar asked Oct 15 '22 10:10

Alexandr Mazanov


1 Answers

You are not alone! It's not something you are doing wrong, if you disable "Allow External Storage" option (and delete the app from your device to avoid migration crash) it will sync fine. Obviously it's something wrong with "Allow External Storage" option, and files bigger than a few mb.

In my app I was syncing png images. Those who were bigger than ~28mb (if I can recall the size correctly), couldn't sync to a device and made it crash.

I submitted a bug report with Feedback Assistant, and for the first time Apple asked for more details. I send them a sample app.

Edit: Good news folks! Apple flagged my bug report with "Potential fix identified - For a future OS update". I'll check Xcode 12 beta if its fixed and report back.

Edit 2: For iOS 14 and Xcode 12, the bug has been fixed! Yay! 🎉

like image 158
Nikos Polychronakis Avatar answered Oct 21 '22 02:10

Nikos Polychronakis