質問

I have a "Shoebox" Mac app with a UIDocument based iOS counterpart.

I'm trying to figure out the best strategy to synchronize data between Mac and iOS via iCloud.

I can't adopt NSDocument in the Mac app (it's a shoebox app without the concept of separate documents similar to albums in iTunes).

My plan for the Mac app is this:

  • Store each item as file package in a "data" directory
  • Use file wrappers to write the package
  • Use file coordination to synchronize read/write operations (sync on the "root" folder of the file package)

For the iOS app:

  • Load the file packages that the Mac app created in the data directory as UIDocuments
  • Rely on UIDocument for change notifications/file coordination
  • I won't use the Documents folder, because I don't want the user to see the documents in the Settings app

My questions:

  • How can I ensure that my file packages from the Mac are synchronized in a consistent way to iOS? (i.e. changes to multiple files in a package are treated atomically as one change)
  • Is it enough to set the "file package" bit on the directory (I actually do this by exporting a UTI)?
  • Is there a way to actually simulate/test this?
役に立ちましたか?

解決

You're in for a world of heck, here. There's no magic bullet to synchronizing file packages between machines—there are too many unsolved problems that iCloud syncing glosses over. What happens when half the data files in your package write out and then the user shuts off her computer and the rest don't write? What if the main index file is read from the net correctly but the net fails before any of the data files it refers to are loaded?

As far as I know iCloud doesn't do anything to deal with these kinds of issues.

But, that said, even with a shoebox app I would (and did) use NSDocument. It's not very much work to get it to do what you want, and you get so much stuff for free. Like, just rip the "open" and "save" menu items out of your main menu, and tell the NSDocumentController to open your data file when the app launches. That's what we do.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top