2011-12-14 58 views
14

我遇到問題,即使用戶在設置中正確設置了所有內容,URLForUbiquityContainerIdentifier在某些情況下仍會返回nil。我的代碼:即使配置正確,URLForUbiquityContainerIdentifier也會返回零

dispatch_async(someQueue, ^{ 

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

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

}); 

有沒有人遇到同樣的問題?我將nil設置爲應該根據Apple文檔工作的容器標識符,但我不再相信這一點。此外,這段代碼對於大多數用戶來說工作得很好,但不知何故不適合每個人。

+1

一個用戶只是報告說,它在安裝的iOS 5.1 Beta 2中 – 2011-12-14 14:36:34

+0

有同樣的問題,這個方法總是返回零 – 2012-02-07 21:23:42

+0

我現在設置正確的容器標識後工作。這沒有效果。仍有一些用戶遇到此問題。在設備 – 2012-02-08 20:31:09

回答

3

我想看看你的entitlement.plist上的一個程序,我需要改變$(TEAMID)在配置文件中的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"]; 
} 
0

如果您仍有問題,請確保您在模擬器上運行的設備上不會總是返回有效值。 我試過你在我的應用程序上的代碼,我沒有得到零

8

檢查你已啓用iCloud容器在你的權利。啓用授權時,默認情況下不會添加容器。單擊Target/Summary/Entitlements中的「+」號添加您的appId。

2

URLForUbiquityContainerIdentifier alway return nil

NSURL *ubiquityURL = [fileManager URLForUbiquityContainerIdentifier:nil]; if (ubiquityURL == nil) 
  • 應用程序通過xcode4.5
  • 應用打造的是使icloud的
  • 的IOS是loginned iCloud帳戶

ubiquityURL處於調試正常,但ubiquityURL是在發佈到appstore後總是零。

8

iPad mini with iOS7。我剛剛經歷過那個URLForUbiquityContainerIdentifier突然開始返回nil。我嘗試重新啓動設備,但它沒有幫助。

在Settings應用程序的「iCloud」菜單下。我注意到'文檔&數據'被設置爲關。

解決方案是將'Documents & Data'更改爲'On'。

1

今天我又遇到了這個問題。

這次是因爲我的配置文件無效。

Invalid provisioning profile

開發人員網站上,我不得不產生一個新的供應配置文件。之後在Xcode5中重新加載配置文件。現在URLForUbiquityContainerIdentifier再次返回有效的網址。

7

如果有人具有使用該iOS8上貝塔同樣的問題,似乎有與所述授權是在Xcode 6中產生的方式中的錯誤。我敲我的頭這幾天,直到通過這篇文章來在蘋果開發者論壇:https://devforums.apple.com/thread/229509?

從本質上講,Xcode中生成一個名爲com.apple.developer.icloud-container-identifiers鍵時,它應該是com.apple.developer.ubiquity-container-identifiers無處不,不icloud的)。當它應該是$(TeamIdentifierPrefix).$(CFBundleIdentifier)時,它也可能具有設置爲iCloud.$(CFBundleIdentifier)的值。

當然,這可能會固定在未來的測試階段,但讓任何困惑,我希望這會有所幫助。

0

啓用「iCloud的驅動器」在iPhone的設置

相關問題