【问题标题】:iOS - How to know if iCloud photo transfer ability is enablediOS - 如何知道是否启用了 iCloud 照片传输功能
【发布时间】:2011-12-22 16:17:51
【问题描述】:

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

【问题讨论】:

  • 您是在谈论 Photo Stream 还是在谈论 iCloud 备份?
  • @MichaelDautermann :我说的是照片流,但是阅读您的评论,我说的是任何可能以可读方式将 iPhone 照片发送到 iCloud 的手段,所以我猜备份是在那个范围内。

标签: iphone image settings ios5 icloud


【解决方案1】:

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

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

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

【讨论】:

  • 如果我的应用程序拍摄的照片将存储在 iCloud 上,我只想显示一个通知。
【解决方案2】:

只要你在下面提供一个有效的泛在容器标识符,方法应该返回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:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 2021-07-20
    相关资源
    最近更新 更多