簡體   English   中英

Swift - 無法連接到 iCloud 文檔

[英]Swift - Can't connect to iCloud documents

我正在嘗試使用 iCloud 文檔來存儲來自 iOS 應用程序(Xcode 11.3 和 Swift 5)的備份文件。

我設置了 iCloud 功能的基礎,但無法獲取容器的 URL。

這是 iCloud 功能設置在此處輸入圖片說明

權利文件在此處輸入圖片說明

Info.plist中添加的key

<key>NSUbiquitousContainers</key>
    <dict>
        <key>iCloud.com.alienfamily.TestiCloudAgain</key>
        <dict>
            <key>NSUbiquitousContainerIsDocumentScopePublic</key>
            <true/>
            <key>NSUbiquitousContainerName</key>
            <string>myCloudTest</string>
            <key>NSUbiquitousContainerSupportedFolderLevels</key>
            <string>Any</string>
        </dict>
    </dict>

我試過的代碼

let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")

if iCloudDocumentsURL != nil {
    print("All good")
} else {
    print("I'm sad")
}

我遵循了許多教程(如本教程)並檢查了其他帖子( stackoverflow ),但沒有任何結果。

有誰知道我做錯了什么?

我的解決方案非常簡單,它是在我的 iPhone 上測試它,該 iPhone 的帳戶設置正確,而不是在模擬器上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM