iOS - How to know if iCloud photo transfer ability is enabled

∥☆過路亽.° 提交于 2019-12-01 16:49:33

问题


The new iCloud service has many possible configurations. How may I know if the device of my user is configured to send taken pictures to an iCloud server instead of storing them just on the device ?


回答1:


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

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

This can give you a hint if iCloud is available at all. If you want to use iCloud to store pictures you can build your own stuff. I'm not really sure what you are planning to do.




回答2:


As long as you give a valid ubiquity container identifier below 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've found that calling URLForUbiquityContainerIdentifier: might take time (several seconds) the very first time within a session. So, just make sure you call this in the background to not block the UI temporarily:

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];
        }
    });
});


来源:https://stackoverflow.com/questions/8020836/ios-how-to-know-if-icloud-photo-transfer-ability-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!