I couldn't get iCloud root directory ("iCloud Drive not available or user domain not found."). Anybody had similar issue? I don't want to CloudKit.
Xcode: Version 16.0 I have done below:
- Settings > iCloud Backup ON
- Settings > iCloud > iCloud Drive ON
- Settings > iCloud > MyApp ON
import Foundation
import UIKit
class BackupManager {
var isiCloudEnabled: Bool {
(FileManager.default.ubiquityIdentityToken != nil)
}
// Get the iCloud Drive folder and create a folder if needed
func createFolder() -> URL? {
let fileManager = FileManager.default
// Access the iCloud Drive root directory (user-visible folder)
guard let iCloudRootURL = fileManager.url(forUbiquityContainerIdentifier: nil)?
.appendingPathComponent("Documents") else {
print("iCloud Drive not available or user domain not found.")
return nil
}
// Check if the folder exists in iCloud Drive root, if not, create it
if !fileManager.fileExists(atPath: iCloudRootURL.path) {
do {
try fileManager.createDirectory(at: iCloudRootURL, withIntermediateDirectories: true, attributes: nil)
print("Folder created in iCloud Drive")
} catch {
print("Error creating folder: \(error.localizedDescription)")
return nil
}
}
// Return the URL of the folder in iCloud Drive
return iCloudRootURL
}
}