1

I have been trying to retrofit a large app to have it store its files in iCloud. The app is not really "Document-based" but the files may be thought of as configuration or preference files.

To be honest I haven't followed all the Apple iCloud guidelines. Some really don't fit in with the flow of the app. When the app starts I read the files from the ubiquity directory (using normal file reads) and when I write them I use a normal file write to the ubiquity directory. When the app start, I also call:

[fileManager startDownloadingUbiquitousItemAtURL:url error:&error];

I do have an NSFilePresenter watching for changes in the ubiquity directory. It notifies me of file changes but there are never any conflict notifications.

My problem is that often when I upload a file to iCloud, it will create a separate file with a number appended. E.g.

MyFile.skyset
MyFile 2 .skyset

These seem to show up when more than one app has been writing MyFile.skyset to the ubiquity directory.

They don't seem to be conflicted file versions. If I use NSFileVersion to look for conflicts and other versions, I only see the one version of MyFile.skyset and it is not in conflict.

I can't find any documentation that explains what this "versioned" file is and what to do about it. Any thoughts as to what is going on here?

btschumy
  • 1,435
  • 1
  • 18
  • 35

1 Answers1

0

Well, I don't fully understand the "versions" but the problem was solved by changing how I updated the files in the ubiquity directory.

I changed from:

[fileMgr removeItemAtPath:dstPath error:nil];
[fileMgr copyItemAtPath:srcPath toPath:dstPath error:&error];

To:

NSData *data = [NSData dataWithContentsOfFile:srcPath];
[data writeToFile:dstPath atomically:NO];

I looks like the operation of deleting the file before copying the updated information to the ubiquity directory was confusing the system. After switching to the second form I'm no longer seeing this problem.

Hope this answer helps someone else.

btschumy
  • 1,435
  • 1
  • 18
  • 35