问题
I have created a database (IOS 5.1) with XCode 4.3.3 for the iPad and have set it up so that the user can backup and restore the database file (*.sqlite) to DropBox. Everything works fine...
Now I would like to do the same process but, set it up for iCloud. Looking for the following function:
- Tap a button to backup the *.sqlite file from the Apps Document Directory up to iCloud at users preference.
- Tap a button to copy the *.sqlite file down from iCloud to the Apps Document Directory.
I have been struggling trying to find the solution, any help will be greatly appreciated.
回答1:
For moving any file to and from icloud you can use this code below.
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:your iCloudURL destinationURL:localDirectoryURL error:&errorsss];
only thing is if you are moving to icloud the code should be :
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:localDirectoryURL destinationURL:your_iCloudURL error:&errorsss];
and if you are getting it from iCloud to Apps Documents directory
[[[NSFileManager alloc]init] setUbiquitous:NO itemAtURL:your_iCloudURL destinationURL:localDirectoryURL error:&errorsss];
来源:https://stackoverflow.com/questions/12083327/ios-5-1-backup-restore-app-file-from-documents-directory-to-from-icloud