Production licenses can be applied in one of two ways:
- Using a license string.
- Using a user authentication workflow.
The option you choose will depend on the nature of your app and whether your app's users will sign in to your app using an ArcGIS account.
License string
A license string is a text string provided by Esri that is used to enable a production license.
Your app must include code to apply the license string. See how to use a license string in your app for more details.
Use a license string if your users or the app fall under one of the following categories:
- Users do not have an ArcGIS account with an ArcGIS Online organization or on-premises ArcGIS Enterprise portal.
- Your app makes use of SDK capabilities before a user signs in with their ArcGIS account.
- Your app will remain offline indefinitely, or will function if offline for a duration of more than 30 days.
Your free Lite level license string is obtained from the ArcGIS Location Platform site (sign in required). Basic, Standard, and Advanced license strings are purchased as ArcGIS Runtime license deployment packs. See get a license for more information.
A Lite license string includes unlimited production deployments.
For Basic, Standard, and Advanced license strings, the ArcGIS Runtime license deployment pack defines how many production deployments are permitted (a deployment is counted per app, install, and user).
User authentication
User authentication is an authentication method where a user signs in to your app with an ArcGIS account in ArcGIS Online or ArcGIS Enterprise. The ArcGIS account of the user can be assigned a production license.
Your app should allow a user to sign in using their ArcGIS account, and must include code to read and apply the license associated with their authenticated account. See how to use user authentication in your app for more information.
The administrator of the ArcGIS organization to which your app user belongs must assign a suitable ArcGIS Runtime license to your app user's ArcGIS account. See get a license for more information.
The production license obtained from user authentication travels with the user, not the app, allowing a user to license many apps.
How to use a license string in your app
You can get your Lite license string for free by signing into your ArcGIS Location Platform account.
Your Runtime Lite license string
Using a license string involves adding code to set the license level at compile time so that the license string is built into the application.
- Find a location in your code that runs before any SDK functionality is used.
- Call the
setlicense(from:)
method on theArcGISEnvironment
singleton object to license the app with a license string and any extension licenses.
// License the app with the supplied license string.
guard let licenseKey = LicenseKey("runtimelite,1000,rud#########,day-month-year,####################") else { return }
do {
let result = try ArcGISEnvironment.setLicense(with: licenseKey)
print("License Result : \(result.licenseStatus)")
} catch {
print(error)
}
Your app is now licensed for production use.
How to use user authentication in your app
Use of user authentication involves adding code to enable sign in with an ArcGIS account. At runtime, a user must successfully sign in to return their license information, which is used by the app to set the license level. Follow these steps to license your app using the member's account:
- Find a location in your code that runs before any SDK functionality is used.
- Allow the app user to authenticate with an ArcGIS organizational account. Upon loading the
Portal
obtain theLicenseInfo
and use this to license the app.
The following example shows how to get a license for an ArcGIS Online member.
// Constructs the portal class and ensure that the user provides their credentials.
let url = URL(string: "https://myportal.com")!
// Requests that the user logs in with their credentials.
let portal = Portal(url: url, connection: .authenticated)
// Loads the portal.
do {
try await portal.load()
// Gets the member's license info from the portal.
let licenseInfo = try await portal.licenseInfo
// Sets the license using the member's licenseInfo.
result = try ArcGISEnvironment.setLicense(from: licenseInfo)
// The app is now licensed.
// Creates a keychain item and saves the license information so that the app can be started and licensed offline.
let licenseInfoData = licenseInfo.toJSON().data(using: .utf8)!
let label = "com.your_org.your_app_name".data(using: .utf8)!
let keychainItem: [String: Any] = [kSecClass as String: kSecClassKey,
kSecAttrLabel as String: label,
kSecValueData as String: licenseInfoData,
kSecUseDataProtectionKeychain as String: true]
status = SecItemAdd(keychainItem as CFDictionary, nil)
} catch {
print(error)
}
Your app is now licensed for production use.