InvalidArgumentError(details: "Mobile map directory path is not an empty directory.")
I am getting above error while try to load offline downloaded map
below is the code snipet
Folder structure Folder structure
import SwiftUI
import ArcGIS
struct OfflineMapViewDetails: View {
@State private var offlineMap: Map?
@StateObject private var offlineMapTaskWrapper: OfflineMapTaskWrapper
var itemId: String
init(itemId: String) {
self.itemId = itemId
_offlineMapTaskWrapper = StateObject(wrappedValue: OfflineMapTaskWrapper(itemId: itemId))
}
var body: some View {
VStack {
if let map = offlineMap {
MapView(map: map)
}
}
.onAppear {
Task {
await offlineMapTaskWrapper.generateOfflineMap() { map in
self.offlineMap = map
}
}
}
}
}
class OfflineMapTaskWrapper: ObservableObject {
private var offlineMapTask: OfflineMapTask
private let itemId: String
init(itemId: String) {
self.itemId = itemId
let offlinePortalItem = PortalItem(portal: PortalManager.shared.portal!, id: PortalItem.ID(rawValue: itemId)!)
self.offlineMapTask = OfflineMapTask(portalItem: offlinePortalItem)
}
func getDirectoryPath() -> URL {
let baseDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
return baseDirectory.appendingPathComponent(itemId)
}
func generateOfflineMap( completion: @escaping (Map) -> Void) async {
let parameters = GenerateOfflineMapParameters()
parameters.includesBasemap = true
// parameters.areaOfInterest = extent
parameters.continuesOnErrors = false
let temporaryDirectory = getDirectoryPath()
print("temporaryDirectory: \(temporaryDirectory)")
print("temporaryDirectory: \(offlineMapTask.portalItem?.id)")
print("temporaryDirectory: \(PortalManager.shared.portal?.user?.fullName)")
let generateOfflineMapJob = offlineMapTask.makeGenerateOfflineMapJob(
parameters: parameters,
downloadDirectory: temporaryDirectory
)
generateOfflineMapJob.start()
do {
let output = try await generateOfflineMapJob.output
let map = output.offlineMap
//let builder = EnvelopeBuilder(envelope: extent)
// builder.expand(by: 0.8)
// map.initialViewpoint = Viewpoint(boundingGeometry: builder.toGeometry())
DispatchQueue.main.async {
completion(map)
}
} catch {
print(error)
}
}
}
Based off the screenshot of the folders, you already have a downloaded map on disk at the location you're trying to download to. When you specify the download location, you should make sure there isn't already something at that location on disk.
There are two things you can do:
Hope that helps.