nothirst / TICoreDataSync

Automatic synchronization for Core Data apps, between any combination of Mac OS X and iOS: Mac to iPhone to iPad to iPod touch and back again.
https://github.com/nothirst/TICoreDataSync/wiki
807 stars 61 forks source link

[iCloud] Not finding remote file structure on first run #69

Open agrigg opened 11 years ago

agrigg commented 11 years ago

When using the iCloud sync manager, it is not finding the remote file structure, even though it exists and so the delegate method didPauseRegistrationAsRemoteFileStructureDoesNotExistForDocumentWithIdentifier is being called. It looks like in the checkWhetherRemoteGlobalAppDirectoryExists method in TICDSiCloudBasedApplicationRegistrationOperation, it is just doing a simple fileExistsAtPath call. It looks like iCloud has the files, but hasn't downloaded them to the local device. Is there a way to force iCloud to pull down the sync files before running the sync registration or change the checkWhetherRemoteGlobalAppDirectoryExists to use an NSMetatdataQuery instead?

MrRooni commented 11 years ago

Austin,

I'm not sure on this one, let me see if I can get some help.

best, Michael

agrigg commented 11 years ago

Okay, thanks. I asked a question about NSMetadataQuery on Stackoverflow

http://stackoverflow.com/questions/17499331/how-do-i-determine-if-file-exists-in-icloud-folder

It sounds like this isn't really possible to know for sure if there are existing files on iCloud. The best I know to do at this point is to use the NSMetadataQuery and time out after 15-30 seconds and assume there are no files at that point. Not a great user experience, but that should only happen the first time they enable syncing on a device.

drewmccormack commented 11 years ago

I've just shipped my app Mental Case with TICD/iCloud sync. First sync is one of the weaknesses of the current setup, I'm afraid.

The way I have done it, I use a class called TIUbiquityMonitor in External Sources to wait for all data to download from iCloud. It is basically a glorified wrapper for NSMetadataQuery, but will count up how much data is not downloaded, and can even be used to activate downloads if they aren't already. This class may not be in the main branch of TICDS. If not, you can find it in my fork (drewmccormack).

The idea is just to try to download all the data before doing the first sync op. The problem can still arise, as you point out, that the device has not even received the metadata, and doesn't know about any files. There really isn't much you can do about this. What I do is simply state in a message to the user that no data was found. If they expected data to be there, they should just wait. Far from a great experience, but there is no way to force metadata to be retrieved. You could also just pause 30 seconds, as you say. That may catch most of the problems.

agrigg commented 11 years ago

Okay, thanks for the info Drew, good to know the iCloud branch is seeing some real-world use. I'll check out the TIUbiquityMonitor.

One other question for you, how are you handling if someone logs out of iCloud or switches accounts? Are you keeping a separate database per iCloud account or using a fallback store? I wondered if I could even use the preconfigureDocumentSyncManager if someone logs out to keep generating sync changes and then sync those up when they log in again.