I have apps for Mac OS (myMacApp) and iOS (myIOSApp) that use the same file 
format. The apps can synchronize files using WiFi or Dropbox.

Now I’m working on using iCloud for synchronization. I’m using the same 
approach that works with Dropbox, which is:

1. myIOSApp can read from and write to the app folder on Dropbox.

2. If the file has not been previously synced, a copy can be written to Dropbox 
for uploading to myIOSApp.

3. Once copies of the file exist on both platforms, they can be synced after 
one or both has been edited.

4. If the copy in myIOSApp has been edited, that copy is written to Dropbox.

5. In myMacApp, when the sync menu item is selected, myMacApp looks for the 
file (by name) on Dropbox, downloads it and saves it with a temporary file name.

6. The temporary file is compared with the original, and any differences are 
resolved.

7. The temporary file is deleted from the Mac, and myMacApp writes the resolved 
file to Dropbox.

8. myIOSApp reads the resolved file from Dropbox.

I’ve gotten to the point that both myMacApp and myIOSApp can read from and 
write to the same ubiquity container, using NSFileManager routines.

When myMacApp reads files from iCloud, the files have the correct file 
extension, something like this: MyFile.xten

When myIOSApp running on the iPhone reads files that it wrote, the file names 
are fine, but when reading files written by myMacApp, they look like this: 
.MyFile.xten.icloud

I was thinking that I must be missing something regarding how entitlements or 
info.plist were set up for each app, but it turns out that files written by 
myIOSApp running on the iPad are treated the same way. And, myIOSApp running on 
the iPad treats files that were written from the same app running on the iPhone 
the same way.

The ubiquity container can be viewed in Terminal on the Mac by typing ls -r 
"Library/Mobile Documents/iCloud~com~mycompany~myiosapp”

When the files are listed in Terminal, all I see are the file names, with 
nothing to differentiate them based on which app wrote them, nor based on which 
device they came from. None of them have the leading period or the trailing 
.icloud.

I also use the following to create a listing of the files in the ubiquity 
container:

        NSURL *iCloudURL = [[NSFileManager defaultManager] 
URLForUbiquityContainerIdentifier:nil];
        if (iCloudURL)
                NSArray* fileList = [[NSFileManager defaultManager] 
contentsOfDirectoryAtPath:iCloudURL.path error:NULL];

I step through the fileList array and use fprintf to show the paths. They show 
the same problem with the leading period and trailing icloud.

Trying to work around the modified file names hasn’t produced any useful 
results so far. If I read the files with the incorrect name, the content is 
incorrect. If I strip off the the leading period and trailing icloud before 
trying to read, the read fails.

I would appreciate any insights as to the cause of the problem and, of course, 
it’s solution.

Thanks,
Mike Wright

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to