iOS - 如何知道是否启用了iCloud照片传输功能 [英] iOS - How to know if iCloud photo transfer ability is enabled

查看:214
本文介绍了iOS - 如何知道是否启用了iCloud照片传输功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的iCloud服务有许多可能的配置。如何知道我的用户设备是否配置为将拍摄的照片发送到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 ?

推荐答案

只要您在下方提供有效的普遍容器标识符,方法应返回 YES

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

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

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

这篇关于iOS - 如何知道是否启用了iCloud照片传输功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆