URLForUbiquityContainerIdentifier始终返回nil

时间:2015-01-07 17:36:53

标签: ios objective-c xcode icloud

Simulator在iOS8.1中,我正在使用Xcode 6.1.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。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:7)

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

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

相关问题