Я сталкиваюсь с "MCMErrorDomain error 44" примерно в 50% времени в app.launch () при загрузке контейнера в мое приложение. Я понятия не имею, в чем причина, и я не могу найти информацию об этой ошибке.
Это код, который я использую для загрузки контейнера в приложение.
extension AppDelegate {
func loadAppData(appDataPath: String) {
let loaderUrl = URL(fileURLWithPath: #file)
let bundleUrl = URL(fileURLWithPath: appDataPath, relativeTo: loaderUrl).appendingPathExtension("xcappdata")
let contentsURL = bundleUrl.appendingPathComponent("AppData")
let fileManager = FileManager.default
let enumerator = fileManager.enumerator(at: contentsURL,
includingPropertiesForKeys: [.isDirectoryKey],
options: [],
//swiftlint:disable:next force_unwrapping
errorHandler: nil)!
//swiftlint:disable:next force_unwrapping
let destinationRoot = fileManager.urls(for: .libraryDirectory, in: .userDomainMask).last!.deletingLastPathComponent()
let test = fileManager.enumerator(at: destinationRoot,
includingPropertiesForKeys: [.isDirectoryKey],
options: [],
//swiftlint:disable:next force_unwrapping
errorHandler: nil)!
while let lol = test.nextObject() as? URL {
do {
try fileManager.removeItem(at: lol)
} catch {
print("✌️ \(error)")
}
}
print("✌️ \(destinationRoot)")
let sourceRoot = contentsURL.standardizedFileURL.path
while let sourceUrl = enumerator.nextObject() as? URL {
guard let resourceValues = try? sourceUrl.resourceValues(forKeys: [.isDirectoryKey]),
let isDirectory = resourceValues.isDirectory,
!isDirectory else {
continue
}
let path = sourceUrl.standardizedFileURL.path.replacingOccurrences(of: sourceRoot, with: "")
let destinationURL = destinationRoot.appendingPathComponent(path)
do {
try fileManager.createDirectory(at: destinationURL.deletingLastPathComponent(),
withIntermediateDirectories: true,
attributes: nil)
try fileManager.copyItem(at: sourceUrl,
to: destinationURL)
} catch {
print("✌️ \(error)")
do {
_ = try fileManager.replaceItemAt(destinationURL, withItemAt: sourceUrl)
} catch {
print("✌️ \(error)")
}
}
}
print("done")
}
}