Prerequisites
Before starting this tutorial:
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
Your system meets the system requirements.
Steps
You need an access token to use the location services used in this tutorial.
-
Go to the Create an API key tutorial to obtain a new API key access token.
-
Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service.
-
Copy the access token as it will be used in the next step.
-
-
In the Project Navigator, click MainApp.swift.
-
In the Editor, add an
import
statement to reference the API and implement an initializer in theMain
struct.App -
Set the
ArcGIS
property with your API key access token.Environment.api Key
MainApp.swiftUse dark colors for code blocks 2 3 4 6 7 8 9 15 16 17 18 19 20 21 22 23 24 25Add line. Add line. Add line. Add line. Add line. Add line. import SwiftUI import ArcGIS @main struct MainApp: App { init() { ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>") } var body: some SwiftUI.Scene { WindowGroup { ContentView() .ignoresSafeArea() } } }
-
For more information, see API key authentication.
Best Practice: The access token is stored directly in the code as a convenience for this tutorial. In a production environment we do not recommend that you store it directly in source code.