URLForUbiquityContainerIdentifier始终返回nil

5

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

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

但似乎没有任何作用。我的设置如下:

权利和功能: enter image description here

enter image description here

代码:

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测试,而不是在模拟器中。 - rmaddy
1个回答

7

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

根据我的测试,如果iOS 8.1模拟器中未启用iCloud Drive,则URLForUbiquityContainerIdentifier始终返回nil。但是,如果您在具有相同设置的设备上进行测试,则会返回有效值。同样,如果启用了iCloud Drive,则模拟器将返回正确的值。如果您不想启用iCloud Drive,则除了在真实设备上测试之外,没有其他解决方法。


@cohenadair,你有关于“测试用户”的想法吗?代码返回了nil。 - Ofir Malachi
@OfirMalachi 你需要详细说明一下。虽然这是很久以前的事情,但似乎我的所有问题都是通过使用真正的iOS设备而不是模拟器来解决的。 - cohenadair

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接