here i created local root for document storage but i want to implement iCloud.so i need to create iCloud Root and also i will check if iCloud available or not. if it is possible to create like Method. here i added my local root method code
- (NSURL *)localRoot {
if (_localRoot != nil) {
return _localRoot;
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *artdirectoryPath = [documentsDirectory stringByAppendingPathComponent:@"/Me"];
_localRoot=[[NSURL alloc]initFileURLWithPath:artdirectoryPath];
return _localRoot;
}
You find the iCloud "root" directory using:
NSURL *url = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
If you have only one ubiquity container for your app, you can pass nil
for the argument, otherwise you must pass the container identifier.
You can also use this to check if iCloud is available to your app-- if it returns nil
, you can't use iCloud. It's not the best way to check for availability though, because it can block for a while. For a quick, non-blocking check, use this:
id token = [[NSFileManager defaultManager] ubiquityIdentityToken];
And then be sure to observe NSUbiquityIdentityDidChangeNotification
in case the availability changes.
However: this is nowhere near enough to start using iCloud for documents. You can't just read/write files in that directory and have iCloud do the right thing. At an absolute minimum you'll need:
NSMetadataQuery
to find documents that exist on the cloud server but are not downloaded locally.-[NSFileManager startDownloadingUbiquitousItemAtURL:error:]
to tell iCloud to begin downloading documents you've found with the metadata query.NSFileCoordinator
, and notifications of changes via NSFilePresenter
.Apple has a lot of documentation, and videos from WWDC that will help with this.