URLForUbiquityContainerIdentifier returns nil even if configured correctly

99封情书 提交于 2019-12-18 12:56:22

问题


I am having the problem, that URLForUbiquityContainerIdentifier is returning nil in some cases even if the user has set up everything correctly in the settings. My code:

dispatch_async(someQueue, ^{

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

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

});

Does anybody came across the same problem? I am setting nil as the container identifier which should work according to the Apple docs, but I am not so convinced anymore about that. Also this code works fine for the majority of users, but somehow not for everybody.


回答1:


Check that you have enabled iCloud containers in your entitlement. The containers are not added by default when you enable entitlements. Click the "+" sign in Target/Summary/Entitlements to add your appId.




回答2:


iPad mini with iOS7. I just have experienced that URLForUbiquityContainerIdentifier suddenly started to return nil. I tried restarting the device, but it didn't help.

Inside the Settings app, under the 'iCloud' menu. I noticed that 'Documents & Data' was set to Off.

Solution was to change 'Documents & Data' to 'On'.




回答3:


If anyone is having the same problem using the iOS8 Betas, there seems to be a bug with the way the Entitlements are generated in Xcode 6. I was banging my head against this for days until coming across this post in the Apple Developer Forums: https://devforums.apple.com/thread/229509?

Essentially, Xcode generates a key named com.apple.developer.icloud-container-identifiers when it should be com.apple.developer.ubiquity-container-identifiers (ubiquity, not icloud). It may also have the value set as iCloud.$(CFBundleIdentifier) when it should be $(TeamIdentifierPrefix).$(CFBundleIdentifier).

Of course this may get fixed in the next Beta but for anyone as confused as me I hope this helps.




回答4:


I'd look at your entitlement.plist on one app I needed to change $(TEAMID) to profile id the numbers and letter before the dns in the profile - here is some code that will work with 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"];
}



回答5:


URLForUbiquityContainerIdentifier alway return nil

NSURL *ubiquityURL = [fileManager URLForUbiquityContainerIdentifier:nil]; if (ubiquityURL == nil)
  • app build by xcode4.5
  • app is enable icloud
  • ios is loginned icloud account

ubiquityURL is normal in debug, but ubiquityURL is always nil after distribution to appstore.




回答6:


Today I experienced this problem again.

This time it was because I had an invalid provisioning profile.

On the developer site, I had to generate a new provisioning profile. Afterward reload the provisioning profiles within Xcode5. Now URLForUbiquityContainerIdentifier again returns valid urls.




回答7:


If you still having issue o make sure you are running on a device as simulator wont always return a valid value . I tried you code on my app and Im not getting nil




回答8:


Enable "iCloud Drive" in the iPhone's Settings



来源:https://stackoverflow.com/questions/8505307/urlforubiquitycontaineridentifier-returns-nil-even-if-configured-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!