URLForUbiquityContainerIdentifier始终返回nil

coh*_*air 4 xcode objective-c ios icloud

模拟器在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
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

我的Apple ID已启用iCloud进行开发和分发; 我尝试过创建和下载新的配置文件.

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

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

Iai*_*nus 7

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

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