As long as you give a valid ubiquity container identifier below, the method should return YES :
static NSString *UbiquityContainerIdentifier = @"ABCDEFGHI0.com.acme.MyApp"; - (BOOL) iCloudIsAvailable { NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *ubiquityURL = [fileManager URLForUbiquityContainerIdentifier:UbiquityContainerIdentifier]; return (ubiquityURL) ? YES : NO; }
However, I found that calling URLForUbiquityContainerIdentifier: may take time (several seconds) for the first time in a session. Therefore, just make sure you call this in the background so as not to temporarily block the user interface:
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(backgroundQueue,^{ BOOL isAvailable = [self iCloudIsAvailable] dispatch_async(dispatch_get_main_queue(),^{ if (!isAvailable){ UIAlertView *alert = [[UIAlertView alloc] init...] [alert show]; [alert release]; } }); });
source share