iphone - URLForUbiquityContainerIdentifier 是否为 : return nil when network access is not available?

标签 iphone objective-c ios ipad ios5

当处于飞行模式或网络访问不可用的任何其他状态时,调用 NSFileManager 的 URLForUbiquityContainerIdentifier: 会返回 nil 吗?

对此的后续问题是:如果对 URLForUbiquityContainerIdentifier: 的调用没有返回 nil,而是在网络访问不可用时返回有效的 URL,这是一种访问云的方式吗离线基于文档?

Apple 文档声明如果未配置或未启用 iCloud,这将返回 nil。它没有提到如果网络访问不可用会发生什么。

我会自己测试这个,但据我所知,我必须在实际设备上测试它,而目前我无法在设备上进行测试。谢谢!

最佳答案

UbiquityContainer 是一个本地存储容器,其中包含您从 iCloud 请求的文档。当网络不可用时,此容器可用。通过使用以下示例

NSURL *ubiq = [[NSFileManager defaultManager] 
  URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
    NSLog(@"iCloud access at %@", ubiq);
    // TODO: Load document... 
} else {
    NSLog(@"No iCloud access");
}

即使手机处于飞行模式,您也可以访问文件和通用容器。当网络连接恢复时,icloud 守护程序将自动同步文件,即使在后台也是如此。

这是一篇关于 iCloud 设置的精彩文章。 http://www.raywenderlich.com/6015/beginning-icloud-in-ios-5-tutorial-part-1

关于iphone - URLForUbiquityContainerIdentifier 是否为 : return nil when network access is not available?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050765/

相关文章:

iphone - 在 iPhone 上进行多线程有意义吗?

iphone - 替换为 view2 后删除 View 1

iphone - UIView block 动画转换与显示/隐藏键盘上的动画内容

ios - UITableView pull-to-add 交互模式

ios - AFHTTPSessionManager 子类 : Post API with body.

ios - 我应该如何使用 RxSwift 更新 UITableViewCell?

iphone - UIView 的简单核心动画 3D 变换

ios 7 标签栏 Controller -> morenavigationcontroller barStyle & color

ios - 将 UIImageView 动态添加到 UIScrollview 中,但无法自动调整大小

ios - 在 UITextView 中的 attributeText 中使用 html 时删除控制字符(回车、格式化?等)