iOS Native — MapLibre Native iOS
Full native UIKit + SwiftUI integration. For Swift code idioms see ../integrations/swift.md.
Install (SPM)
In Xcode → File → Add Package Dependencies:
https://github.com/maplibre/maplibre-gl-native-distributionPin minimum version 6.0.0.
Info.plist
Store your key in Info.plist (or use Xcode build settings → Configuration files):
xml
<key>MFDPublicKey</key>
<string>mfd_pub_xxxxxxxx</string>UIKit map
swift
import UIKit
import MapLibre
class MapVC: UIViewController {
private var mapView: MLNMapView!
override func viewDidLoad() {
super.viewDidLoad()
let key = Bundle.main.object(forInfoDictionaryKey: "MFDPublicKey") as! String
let url = URL(string: "https://api.mapsfordevs.com/styles/standard.json?key=\(key)")!
mapView = MLNMapView(frame: view.bounds, styleURL: url)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.setCenter(CLLocationCoordinate2D(latitude: -26.20, longitude: 28.04),
zoomLevel: 11, animated: false)
mapView.showsUserLocation = true
view.addSubview(mapView)
}
}SwiftUI wrapper
swift
import SwiftUI
import MapLibre
struct MapLibreView: UIViewRepresentable {
let styleURL: URL
let center: CLLocationCoordinate2D
let zoom: Double
func makeUIView(context: Context) -> MLNMapView {
let v = MLNMapView(frame: .zero, styleURL: styleURL)
v.setCenter(center, zoomLevel: zoom, animated: false)
return v
}
func updateUIView(_ v: MLNMapView, context: Context) {}
}
struct ContentView: View {
let key = Bundle.main.object(forInfoDictionaryKey: "MFDPublicKey") as! String
var body: some View {
MapLibreView(
styleURL: URL(string: "https://api.mapsfordevs.com/styles/standard.json?key=\(key)")!,
center: CLLocationCoordinate2D(latitude: -26.20, longitude: 28.04),
zoom: 11
).edgesIgnoringSafeArea(.all)
}
}Markers + popup
swift
let pin = MLNPointAnnotation()
pin.coordinate = CLLocationCoordinate2D(latitude: -26.20, longitude: 28.04)
pin.title = "Office"
pin.subtitle = "Open 9-17"
mapView.addAnnotation(pin)Offline .mfdmap (downloads API)
For offline maps, use the Downloads API to fetch a .mfdmap, then point MapLibre at the local PMTiles via the pmtiles:// protocol handler. See ../recipes/offline.md.
App attest
Register your bundle ID in the dashboard against your mfd_pub_* key. The SDK posts the bundle ID in the User-Agent header automatically; we validate against the allow-list.