mapbox / mapbox/mapbox-navigation-ios
[Bug]: Offline Map not visible
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 918
- Forks
- 326
- Avg merge
- 1h 16m
- Merged PRs (30d)
- 3
Description
### Mapbox Navigation SDK version
3.25.1
### Steps to reproduce
Hi,
I'm implementing Mapbox in my app, and since some routes need to work offline, I'm implementing offline navigation. The user can download routes from a list of GPX files that belong to a travel itinerary. After downloading the selected route and its offline map data, the user should be able to display the route and start navigation without an internet connection. However, I'm encountering an error when displaying a route and starting navigation while offline.
Here's the download code:
```
func downloadRegion(
region: OfflineRegion,
downloadingRegions: Set,
onDownloadingRegionsUpdate: @escaping (Set) -> Void,
onProgress: @escaping (String, Float) -> Void,
onCompletion: @escaping (String, Result) -> Void
) {
guard !downloadingRegions.contains(region.id) else {
return
}
let tileStore = TileStore.default
let offlineManager = OfflineManager()
let tilesetDescriptor = offlineManager.createTilesetDescriptor(
for: TilesetDescriptorOptions(
styleURI: .streets,
zoomRange: 6...16,
tilesets: [
"mapbox://mapbox.mapbox-streets-v8",
]
)
)
let loadOptions = TileRegionLoadOptions(
geometry: region.geometry,
descriptors: [tilesetDescriptor],
metadata: nil,
acceptExpired: true,
networkRestriction: .none
)!
var updatedDownloadingRegions = downloadingRegions
updatedDownloadingRegions.insert(region.id)
onDownloadingRegionsUpdate(updatedDownloadingRegions)
onProgress(region.id, 0.0)
let _ = tileStore.loadTileRegion(
forId: region.id,
loadOptions: loadOptions
) { progress in
let totalResources = max(progress.requiredResourceCount, 1)
let progressValue = Float(progress.completedResourceCount) / Float(totalResources)
onProgress(region.id, progressValue)
} completion: { result in
updatedDownloadingRegions.remove(region.id)
onDownloadingRegionsUpdate(updatedDownloadingRegions)
onCompletion(region.id, result)
}
}
```
The safety data check performed after the download confirms that the region has been stored.
```
private func downloadDataCheck() {
let tileStore = TileStore.default
tileStore.tileRegion(forId: regionID) { result in
DispatchQueue.main.async {
switch result {
case .success(let tileRegion):
self.isDownloaded = true
debugPrint("MB \(Double(tileRegion.completedResourceSize) / (1024 * 1024))")
case .failure(_):
self.isDownloaded = false
onDownloadedChange?(false, 0.0)
}
}
}
}
```
### Expected behavior
After the offline region download completes, I expect the downloaded area to be displayed when I open the map. Instead, I only see an empty world, and even if I zoom into the downloaded area, no map content is rendered.
I'm not sure if I'm missing an initialization step or if the map needs to be displayed at least once while online before the offline tiles can be rendered correctly. In fact, if I open the map once with network connectivity, the downloaded area is then displayed correctly in offline mode as well.
### Actual behavior
As I mentioned earlier, when I open the map, only a blank globe is displayed, and I see several errors in the console.
`[Warning, tile_store]: Option `allow-in-memory-download` is not recognized and will be ignored.`
```
Task <6F24D1BF-28F7-4DA6-9F0A-B78605202458>.<730> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x11f95dce0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=50, _NSURLErrorNWResolutionReportKey=Resolved 0 endpoints in 1ms using unknown from cache, _NSURLErrorNWPathKey=unsatisfied (No network route)}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <6F24D1BF-28F7-4DA6-9F0A-B78605202458>.<730>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <6F24D1BF-28F7-4DA6-9F0A-B78605202458>.<730>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://api.mapbox.com/route-tiles/v2/mapbox/driving-traffic/versions?access_token=******&sku=*****, NSErrorFailingURLKey=https://api.mapbox.com/route-tiles/v2/mapbox/driving-traffic/versions?access_token=****&sku=***, _kCFStreamErrorDomainKey=1}
```
```
[Error, nav-native]: Unable to find the latest version of routing tiles!
[Error, nav-native]: Async config init - Unable to determine the tiles version
[Warning, maps-core]: The outdated resource mapbox://styles/mapbox/standard shall be updated explicitly using Offline API
[Warning, maps-core/style]: Repeated slot 'middle', ignoring
```
Let me know If u need more info.
Thanks in advance.
### Is this a one-time issue or a repeatable issue?
repeatable
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the downloadRegion and downloadDataCheck entry points and reproduce the issue by completing the tile download before opening the map offline. Trace the reported tile-store, routing-tile, and style warnings to determine the missing offline initialization or configuration. Done means the downloaded area renders and navigation starts offline without first opening the map online.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100