12

I am adding iCloud with Core Data to an app that already exists in the app store, so I need to test upgrade scenarios. However, when I delete my app from my device and re-install it from Xcode, I have noticed that everything inside of my ubiquity container folder on the device is persisted! This is incredibly annoying, as iCloud ends up getting confused when trying to upload files from the transaction logs directory I have specified and often times out. I end up needing to specify a new transaction log location to get it to work again, which will obviously not work in the future for my testing.

The following is the error I receive:

PFUbiquitySafeSaveFile waitForFileToUpload:: CoreData: Ubiquity: (0) permanentLocation: : /private/var/mobile/Library/Mobile Documents/XXXXXXXXXX~appnamegoeshere/DatabaseTransactionLogs/mobile.8A0C3F8A-4077-57D7-8250-6BE15D1BCD20/iCloudData/8u0BfiCwOkHHa~o8hF4bunW~zmdS_C8om5efuugxRaA=/receipt.0.cdt safeLocation: : /private/var/mobile/Library/Mobile Documents/XXXXXXXXXX~appnamegoeshere/DatabaseTransactionLogs/mobile.8A0C3F8A-4077-57D7-8250-6BE15D1BCD20/iCloudData/8u0BfiCwOkHHa~o8hF4bunW~zmdS_C8om5efuugxRaA=/mobile.8A0C3F8A-4077-57D7-8250-6BE15D1BCD20.0.cdt currentLocation: : /private/var/mobile/Library/Mobile Documents/XXXXXXXXXX~appnamegoeshere/DatabaseTransactionLogs/mobile.8A0C3F8A-4077-57D7-8250-6BE15D1BCD20/iCloudData/8u0BfiCwOkHHa~o8hF4bunW~zmdS_C8om5efuugxRaA=/mobile.8A0C3F8A-4077-57D7-8250-6BE15D1BCD20.0.cdt

kv: (null)

Safe save failed for file, error: Error Domain=NSCocoaErrorDomain Code=512 "The file upload timed out." UserInfo=0x1e5b6b10 {NSLocalizedDescription=The file upload timed out.}

Does anyone know how to clear out a ubiquity container between app installs? Even removing the ubiquity container from the app settings and republishing it does not fix this issue. A customer in theory would be able to hit this issue just by deleting the app and then deleting their iCloud files for it. This issue has been really frustrating to determine what the cause of the issue is - any suggestions are appreciated!

lehn0058
  • 19,977
  • 15
  • 69
  • 109

2 Answers2

7

After much head pounding, I was able to figured this out. Someone mentioned to me that you are able to see all of your iCloud data for your device if you go to developer.icloud.com and login with your iCloud account. Doing some tests with this, I was able to see that the data on the iCloud server was being deleted immediately when I told it to delete from my device. However, all of the folders and files I had created in my ubiquity container on my device stayed, even if I deleted my app.

My work around was to check when setting up my app for using iCloud for the first time and see if my directories were already in the ubiquity container. If they were, then I manually delete the directories and all of the files in them with the following code:

 [fileManager removeItemAtPath:[[fileManager URLForUbiquityContainerIdentifier:nil] path] error:&error];
lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • How did you determine if you are setting up iCloud for the first time? Save a NSUserDefaults? When you setup for the first time how do you clean up that folder? – Austin Jun 20 '13 at 15:30
  • I checked to see if the folders in my ubiquity container (such as the database file) existed. – lehn0058 Jun 21 '13 at 12:52
  • How did you delete the folder? I tried to delete with `[[NSFileManager defaultManager] removeItemAtPath:path error:&error];` but I get an error – kroger Jan 11 '14 at 04:24
  • I used this: [fileManager removeItemAtPath:[[fileManager URLForUbiquityContainerIdentifier:nil] path] error:&error]; – lehn0058 Jan 13 '14 at 15:50
2

This is how iCloud is supposed to to work. Deleting an app on one device doesn't automatically delete the iCloud data. If the app is still installed on other devices that use the same account, they can still use the data.

If you want to clear out iCloud data during testing, go to Settings --> iCloud, drill down to your app, and delete the data.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • 1
    Yep - that's exactly how I have been clearing out the data. It still leaves that ubiquity folder on my device though which is what is causing the problems. I even modified my app to check to see if that folder still existed to make sure I wasn't crazy, and its always there after I delete the iCloud data from settings. – lehn0058 Jan 23 '13 at 22:40
  • Just having the ubiquity folder exist-- empty-- *should* be fine. If it isn't fine for you, it would be good to update your question with more detail about what exactly goes wrong. – Tom Harrington Jan 24 '13 at 02:10
  • 2
    It not just the ubiquity container. The directories inside of it are still there as well. I think this is what is causing iCloud to get confused, since they exist in the local ubiquity container but not on the iCloud server. This ends up causing a time out when I make the request to add the persistant store coordinator. I will do some more testing to get the exact specifics of what is still left over on the device after deleting the iCloud settings. – lehn0058 Jan 24 '13 at 13:32
  • I updated the question with the error that is being returned. Also, I confirmed that all folders (such as the transaction log folder) remain inside of the ubiquity container location even after the iCloud data has been deleted. – lehn0058 Jan 26 '13 at 15:00