iOS - How to know if iCloud photo transfer ability

2019-02-22 05:42发布

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 ?

2条回答
来,给爷笑一个
2楼-- · 2019-02-22 05:46

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];
        }
    });
});
查看更多
祖国的老花朵
3楼-- · 2019-02-22 05:48

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.

查看更多
登录 后发表回答