URLForUbiquityContainerIdentifier:
Returns the URL for the ubiquity (iCloud) container associated with the specified container identifier, and establishes access to that container.
Parameters
- containerID
- The fully-qualified container identifier for a ubiquity container. The string you specify must not contain wildcards and must be of the form <TEAMID>
.
<CONTAINER>, where <TEAMID> is your development team ID and <CONTAINER> describes the bundle identifier of the container you want to access. of [NSFileManager URLForUbiquityContainerIdentifier]The container identifiers for your app must be declared in thecom.apple.developer.ubiquity-container-identifiers
array of the.entitlements
property list file in your Xcode project.If you specifynil
in this parameter, this method returns the first container listed in thecom.apple.developer.ubiquity-container-identifiers
entitlement array.
Return Value
A URL pointing to the specified ubiquity container, or
nil
if the container could not be located or if iCloud storage is unavailable for the current user or device.Discussion of [NSFileManager URLForUbiquityContainerIdentifier]
You use this method to determine the location of your app’s ubiquity container directories and to configure your app’s initial iCloud access. The first time you call this method for a given ubiquity container, the system extends your app’s sandbox to include that container. In iOS, you must call this method at least once before trying to search for cloud-based files in the ubiquity container. If your app accesses multiple ubiquity containers, call this method once for each container. In OS X, you do not need to call this method if you use
NSDocument
-based objects, because the system then calls this method automatically.
You can use the URL returned by this method to build paths to files and directories within your app’s ubiquity container. Each app that syncs documents to the cloud must have at least one associated ubiquity container in which to put those files. This container can be unique to the app or shared by multiple apps.
Example of [NSFileManager URLForUbiquityContainerIdentifier]
/// test iCloud Access
- (void)initializeiCloudAccess {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if ([[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil] != nil)
NSLog(@"iCloud is available\n");
else
NSLog(@"This Application requires iCloud, but it is not available.\n");
});
}
- (NSURL *)iCloudURL
{
return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
}