NSFileManager *fm = [NSFileManager defaultManager];
NSURL *iCloudDocumentsURL = [[fm URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:@"Documents"];
NSURL *iCloudFileURL = [iCloudDocumentsURL URLByAppendingPathComponent:[doc.fileURL lastPathComponent]];
ok = [fm setUbiquitous:YES itemAtURL:doc.fileURL destinationURL:iCloudRecipeURL error:&err];
NSLog(@"doc moved to iCloud, result: %d (%@)",ok,doc.fileURL.fileURL);
setUbiquitous :itemAtURL:destinationURL:error:
Sets whether the item at the specified URL should be stored in the cloud.
- (BOOL)setUbiquitous:(BOOL)flag itemAtURL:(NSURL *)urldestinationURL:(NSURL *)destinationURL error:(NSError **)errorOut
Parameters
- flag
- Specify
YES
to move the item to iCloud orNO
to remove it from iCloud (if it is there currently). - url
- Specify the URL of the item (file or directory) that you want to store in iCloud.
- destinationURL
- Specify the location in iCloud at which to store the file or directory. This URL must be constructed from a URL returned by the
URLForUbiquityContainerIdentifier:
method, which you use to retrieve the desired iCloud container directory. The URL you specify may contain additional subdirectories so that you can organize your files hierarchically in iCloud. However, you are responsible for creating those intermediate subdirectories (using theNSFileManager
class) in your iCloud container directory. of [NSFileManager setUbiquitous] - errorOut
- On input, a pointer to variable for an
NSError
object. If an error occurs, this pointer is set to anNSError
object containing information about the error. You may specifynil
for this parameter if you do not want the error information.
Return Value of [NSFileManager setUbiquitous]
YES
if the item’s status was updated successfully or NO
if an error occurred. If this method returns NO
and you specified a value for the errorOut parameter, this method returns an error object in the provided pointer.Discussion of [NSFileManager setUbiquitous]
Use this method to move a file from its current location to iCloud. For files located in an app’s sandbox, this involves physically removing the file from the sandbox container. (The system extends your app’s sandbox privileges to give it access to files it moves to iCloud.) You can also use this method to move files out of iCloud and back into a local directory.
Your app must have an active file presenter object configured to monitor the specified file or directory before calling this method. When you specify
YES
for theflag parameter, this method attempts to move the file or directory to the cloud and returns YES
if it is successful. This method also notifies your file presenter of the new location of the file so that your app can continue to operate on it.