Run the Maps SDK for iOS Examples App
Mapbox provides a robust Examples app to show various best practices and techniques for building with the Maps SDK for iOS. This tutorial shows the steps necessary to get the demo app running on an iOS emulator via Xcode in your development environment.
Configure Credentials
Step 1: Log in/Sign up for a Mapbox account
If you haven't done so already, sign up for a Mapbox account and or log in to your existing account.
Step 2: Configure your public token
Create a new file .mapbox
in your user directory (~/.mapbox
) containing a public access token. You can use your default public token for this value.
pk.12345...
Clone the mapbox-maps-ios
repository
The examples app lives in a the Apps/Examples
directory of the Maps SDK for iOS code, available on GitHub. Use git to clone the repository on your development machine.
$git clone git@github.com:mapbox/mapbox-maps-ios.git
Open the Examples Project
- Launch Xcode, then choose File > Open...
- Use the file picker to navigate to the
mapbox-maps-ios
repository. - Choose the folder
mapbox-maps-ios/Apps
.
Now you should see the Examples project successfully loaded in the Project Navigator pane.
Run the App
Be sure you have an iOS emulator selected, then click the Run button. Xcode will build and run the Maps SDK for iOS examples app on your emulator.
You will see a listing with the title and description for each example, grouped by category. Tap each example to explore and learn the capabilities of the Mapbox Maps SDK for iOS, including user location, markers and annotations, camera control and animation, and offline use.
If the app loads but you see a black background where the map should be, this means that the public access token was not properly configured and network requests for Mapbox resources are failing.
A build script reads your public access token from ~/.mapbox
and sets the value MBXAccessToken
in the example app's Info.plist
file.
Try inspecting the Info.plist
to confirm that MBXAccessToken
exists and contains the correct public access token value, then run the app again.
Explore the source code
Each example lives in its own swift file, and you can explore the source code as you preview the examples in the emulator to learn how each example works. You may also want to change values and hot reload the app to change the functionality.
A good first customization might be to update the initial camera settings in BasicMapExample.swift
, the source code for the Display a map view example. See if you can make the map initialize on a different location by updating the center
coordinates in CameraOptions
. You can also experiment with different values for zoom
, bearing
, and pitch
,
Next steps
With the Examples app running locally, you're ready to start exploring all the possibilities of the Maps SDK for iOS as you build maps into your iOS apps. Be sure to explore the SDK's documentation to level up, and share questions and lessons learned in the Mapbox Developer Discord.