阅读背景:

iOS - 如何知道是否启用了iCloud照片传输功能

来源:互联网 

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 ?

新的iCloud服务有许多可能的配置。我如何知道我的用户设备是否配置为将拍摄的照片发送到iCloud服务器而不是仅将其存储在设备上?

2 个解决方案

#1


1  

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

如果您想知道iCloud是否已激活,您只需致电:

 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.

如果iCloud可用,这可以给你一个提示。如果您想使用iCloud存储图片,您可以构建自己的东西。我不确定你打算做什么。

#2


1  

As long as you give a valid ubiquity container identifier below method should return YES:

只要您在下面给出一个有效的普遍容器标识符,方法应该返回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:

但是,我发现调用URLForUbiquityContainerIdentifier:可能会在会话中第一次调用时间(几秒钟)。所以,只需确保在后台调用它以暂时不阻止UI:

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

分享到: