【问题标题】:URLForUbiquityContainerIdentifier always return nilURLForUbiquityContainerIdentifier 总是返回 nil
【发布时间】:2015-03-05 16:32:17
【问题描述】:

模拟器在 iOS8.1 中,我使用的是 Xcode 6.1.1。

我尝试了几个不同来源的解决方案:

似乎没有任何效果。我的设置:

权利和能力:

代码:

dispatch_async(dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
    NSURL *myContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

    // unarchive journal object from iCloud
    if (myContainer != nil) {
        NSString *filePath = [NSString stringWithFormat:@"%@/%@", myContainer.path, ARCHIVE_FILE_NAME];
        self.journal = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];

        // initialize journal from local storage if there's no iCloud archive
        if (self.journal == nil)
            [self initJournalFromLocalStorage];
        else
            [self.journal validateUserDefines];

        self.journal.cloudURL = myContainer;

        dispatch_async (dispatch_get_main_queue (), ^(void) {
            // On the main thread, update UI and state as appropriate
        });
    }
});

我的 Apple ID 已为开发和分发启用了 iCloud;我已经尝试创建和下载新的配置文件。

我还尝试将 .entitlements 中的 iCloud.$(CFBundleIdentifier) 更改为 $(TeamIdentifierPrefix)$(CFBundleIdentifier)。

无论我做什么,URLForUbiquityContainerIdentifier 总是返回 nil。任何帮助表示赞赏!

【问题讨论】:

  • 在真实设备上进行 iCloud 测试,而不是在模拟器中。

标签: ios objective-c xcode icloud


【解决方案1】:

您是否在模拟器上启用了 iCloud Drive?

根据我自己的测试 URLForUbiquityContainerIdentifier 总是返回 nil 如果 iCloud Drive 被 iOS 8.1 模拟器禁用。但是,如果您在具有相同设置的设备上进行测试,它将返回一个有效值。同样,如果启用了 iCloud Drive,那么模拟器将返回正确的值。如果您不想启用 iCloud Drive,那么除了在真实设备上进行测试之外,没有其他解决方法。

【讨论】:

  • @cohenadair 对“测试用户”有任何想法吗?它的回报为零
  • @OfirMalachi 您必须详细说明。这是很久以前的事了,但似乎我所有的问题都通过使用真正的 iOS 设备而不是模拟器解决了。
猜你喜欢
  • 1970-01-01
  • 2013-06-16
  • 2012-02-21
  • 1970-01-01
  • 2017-03-28
  • 2014-08-25
  • 2016-05-17
  • 1970-01-01
相关资源
最近更新 更多