Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does URLForUbiquityContainerIdentifier: return nil when network access is not available?

When in airplane mode or any other state where network access is not available, will a call to NSFileManager's URLForUbiquityContainerIdentifier: return nil?

A follow up question to this is: if this call to URLForUbiquityContainerIdentifier: DOES not return nil but rather returns a valid URL when network access is not available is this a way to access cloud based documents offline?

The apple docs state that this will return nil if iCloud is not configured or not enabled. It does not mention what will happen if network access is not available.

I would test this myself but from what I understand I would have to test this on an actual device and testing on a device is not possible for me at this time. Thank you!

like image 790
Jake Vizzoni Avatar asked Jan 29 '12 03:01

Jake Vizzoni


1 Answers

The UbiquityContainer is a local storage container that contains the documents you requested from iCloud. This container is available when when the network is not. By using the following example

NSURL *ubiq = [[NSFileManager defaultManager] 
  URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
    NSLog(@"iCloud access at %@", ubiq);
    // TODO: Load document... 
} else {
    NSLog(@"No iCloud access");
}

You will be able to access the files and ubiquity container when the phone is even in airplane mode. When the network connections restore the icloud daemon will automatically sync the files even in the background.

Here is a great article on iCloud setup. http://www.raywenderlich.com/6015/beginning-icloud-in-ios-5-tutorial-part-1

like image 78
MobileOverlord Avatar answered Oct 07 '22 16:10

MobileOverlord