iCloud Time out. (using iCloud + Core Data + Magic

2019-04-23 10:45发布

问题:

I started an app test to use Core Data and iCloud (using Magical Records). After a lot of troubles to configure Provisioning Profiles and Entitlements, the app finally runs. After a while the app crash and throw this message::

2012-12-31 03:42:07.079 iCloudTest[252:1103] -[PFUbiquitySafeSaveFile waitForFileToUpload:](268): CoreData: Ubiquity:  <PFUbiquityPeerReceipt: 0x1cd5a420>(0)
permanentLocation: <PFUbiquityLocation: 0x1cd57b30>: /private/var/mobile/Library/Mobile Documents/MA5BADG5AW~com~gazapps~iCloudTest/mobile.4088E03C-763E-5A81-BB1B-64CABAFA73E3/com.gazapps.iCloudTest/v8GumdiUYmkE0aO9iGtPTPHX07qqWk7kRytsQwHKjwU=/receipt.0.cdt
safeLocation: <PFUbiquityLocation: 0x1cd57a80>: /private/var/mobile/Library/Mobile Documents/MA5BADG5AW~com~gazapps~iCloudTest/mobile.4088E03C-763E-5A81-BB1B-64CABAFA73E3/com.gazapps.iCloudTest/v8GumdiUYmkE0aO9iGtPTPHX07qqWk7kRytsQwHKjwU=/mobile.4088E03C-763E-5A81-BB1B-64CABAFA73E3.0.cdt
currentLocation: <PFUbiquityLocation: 0x1cd57a80>: /private/var/mobile/Library/Mobile Documents/MA5BADG5AW~com~gazapps~iCloudTest/mobile.4088E03C-763E-5A81-BB1B-64CABAFA73E3/com.gazapps.iCloudTest/v8GumdiUYmkE0aO9iGtPTPHX07qqWk7kRytsQwHKjwU=/mobile.4088E03C-763E-5A81-BB1B-64CABAFA73E3.0.cdt

kv: (null)

Safe save failed for file, error: Error Domain=NSCocoaErrorDomain Code=512 "The file upload timed out." UserInfo=0x1cd5b7d0 {NSLocalizedDescription=The file upload timed out.}
2012-12-31 03:42:07.083 iCloudTest[252:1103] +[MagicalRecord(ErrorHandling) defaultErrorHandler:](0xe5ac0) Error: The file upload timed out.
2012-12-31 03:42:07.085 iCloudTest[252:1103] +[MagicalRecord(ErrorHandling) defaultErrorHandler:](0xe5ac0) Error Message: The file upload timed out.
2012-12-31 03:42:07.086 iCloudTest[252:1103] +[MagicalRecord(ErrorHandling) defaultErrorHandler:](0xe5ac0) Error Domain: NSCocoaErrorDomain
2012-12-31 03:42:07.087 iCloudTest[252:1103] +[MagicalRecord(ErrorHandling) defaultErrorHandler:](0xe5ac0) Recovery Suggestion: (null)
2012-12-31 03:42:07.089 iCloudTest[252:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x3a7702a3 0x3465f97f 0x3a6bae8d 0xdd453 0x38a6311f 0x38a624b7 0x38a671bd 0x3a743f3b 0x3a6b6ebd 0x3a6b6d49 0x38a842eb 0x338f62f9 0xd101d 0x37f22b20)
libc++abi.dylib: terminate called throwing an exception

I used this method to setup Core Data Stack:

[MagicalRecord setupCoreDataStackWithiCloudContainer:@"XXXXXXXX.com.gazapps.iCloudTest" localStoreNamed:@"PersonDB.sqlite"];

Anyone ever had this problem?

Enviroment:
OSX 10.8.2,
Xcode 4.5.2,
app -> iOS 6,
device -> iPhone 4S

回答1:

Yes, more times than I care to recall.

What this means is that Core Data's internals failed to connect to iCloud in some obscure and undocumented way. There's no recovery path or fix-- you just get to try again later. Those errors don't come from Magical Record or your code, they're an internal Core Data / iCloud failure.

Here's the thing: This does not mean you did something wrong. And the corollary of that is, there is nothing you can do to fix it. When using iCloud with Core Data, this just happens sometimes, and you just have to deal with it. File a bug and pray to whatever god or gods you believe in that they fix it some day. Core Data with iCloud is just fundamentally flaky and you're encountering one of the most maddening parts.

Sometimes it helps to just try the call again. But Magical Record returns void, so detecting failure in code is not as simple as you might hope.

During testing, it might help to delete all of your app's data from iCloud, to start clean. You do this in iOS at Settings --> iCloud --> Storage & Backup --> Manage Storage --> (your app name here) --> Edit --> Delete All. Also be sure to check out http://developer.icloud.com/ to see what's present in the cloud. Also, when you're having problems, be sure to delete your app from the device so that no old data is sitting around.