Prerequisites
Before starting this tutorial:
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
Your system meets the system requirements.
Steps
Your app needs an access token
-
Go to the Create an API key tutorial to obtain a new API key access token
An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. .-
Ensure that the necessary privileges
Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. are enabled for the functionality your app requires. If you need to use basemaps, for example, enable access to the Basemap styles service: 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
importstatement to reference the API and implement an initializer in theMainstruct.App -
Set the
ArcGISproperty 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. Do not store credentials directly in source code in a production environment.