6

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

4

2 回答 2

1

如果你想知道 iCloud 是否被激活,你可以简单地调用:

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

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

于 2011-12-19T12:41:42.940 回答
1

只要您在下面的方法中提供一个有效的普遍存在的容器标识符,就应该返回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];
        }
    });
});
于 2012-07-17T09:56:52.630 回答