即使配置正确,URLForUbiquityContainerIdentifier也会返回nil

Mar*_*ing 14 iphone objective-c ios icloud

我遇到了问题,即使用户在设置中正确设置了所有内容,URLForUbiquityContainerIdentifier在某些情况下返回nil.我的代码:

dispatch_async(someQueue, ^{

    if (![[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]) {
        ErrLog(@"iCloud container not available.");
        return;
    }

    dispatch_async(dispatch_get_main_queue(), ^{
       [...]
    });

});
Run Code Online (Sandbox Code Playgroud)

有人遇到过同样的问题吗?我将nil设置为容器标识符,该标识符应该根据Apple文档工作,但我对此不再那么信服.此代码也适用于大多数用户,但不是每个人都有.

小智 8

检查您是否在权利中启用了iCloud容器.启用权利时,默认情况下不会添加容器.点击目标/摘要/权利中的"+"符号以添加您的appId.


neo*_*eye 8

带iOS7的iPad mini.我刚刚经历过URLForUbiquityContainerIdentifier突然开始返回nil.我尝试重启设备,但没有帮助.

在"设置"应用内,在"iCloud"菜单下.我注意到'Documents&Data'被设置为Off.

解决方案是将"文档和数据"更改为"打开".


Sea*_*anR 7

如果有人在使用iOS8 Betas时遇到同样的问题,那么在Xcode 6中生成Entitlements的方式似乎存在一个错误.在Apple Developer Forums中发布这篇文章之前,我几乎没有碰到这个问题:https:https ://devforums.apple.com/thread/229509?

从本质上讲,Xcode生成一个名称com.apple.developer.icloud-container-identifiers应该是com.apple.developer.ubiquity-container-identifiers(无处不在,而不是icloud).它也可以将值设置为iCloud.$(CFBundleIdentifier)应该的值$(TeamIdentifierPrefix).$(CFBundleIdentifier).

当然,这可能会在下一个测试版中得到修复,但对于像我这样困惑的人,我希望这会有所帮助.


App*_*4 U 3

我会在一个应用程序上查看您的 entitlement.plist 我需要更改 $(TEAMID) 来配置文件 id 配置文件中 dns 之前的数字和字母 - 这是一些可与 UIManagedDocument 一起使用的代码

/// test iCloud Access
- (void)initializeiCloudAccess {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        if ([[NSFileManager defaultManager]
             URLForUbiquityContainerIdentifier:nil] != nil)
            NSLog(@"iCloud is available\n");
        else
            NSLog(@"This Application requires iCloud, but it is not available.\n");
    });
}

- (NSURL *)iCloudURL
{

    return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
}

- (NSURL *)iCloudDocumentsURL
{

    return [[self iCloudURL] URLByAppendingPathComponent:@"Documents"];
}

- (NSURL *)iCloudCoreDataLogFilesURL
{

    return [[self iCloudURL] URLByAppendingPathComponent:@"CoreDataLogs"];
}
Run Code Online (Sandbox Code Playgroud)