IOS - How to Find Out if iCloud Photo Transfer is On

The new iCloud service has many possible configurations. How do I know if my user’s device is configured to send pictures to iCloud instead of storing them on the device?

+6
source share
2 answers

If you want to know if iCloud is activated, you can simply call:

NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil]; if (cloudURL != nil) { // iCloud is available } 

This may give you a hint if iCloud is available at all. If you want to use iCloud for storing images, you can create your own materials. I'm not quite sure what you plan to do.

+1
source

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] /* change to the main queue if you want to do something with the UI. For example: */ dispatch_async(dispatch_get_main_queue(),^{ if (!isAvailable){ /* inform the user */ UIAlertView *alert = [[UIAlertView alloc] init...] [alert show]; [alert release]; } }); }); 
+1
source

Source: https://habr.com/ru/post/900843/


All Articles