Configures the shared Encore instance for use throughout your app. This must be called once, typically in your AppDelegate or SwiftUI App initializer, before using any other SDK methods.
Call configure() before using any other SDK methods. Failure to do so will result in .notInitialized errors.
Signature
public func configure(
apiKey: String,
logLevel: EncoreLogLevel = .none
)
Parameters
| Name | Type | Default | Description |
|---|
apiKey | String | - | Your Public API Key or Universal Sandbox Key from the Encore Dashboard settings |
logLevel | EncoreLogLevel? | .none | Debug logging level |
Log levels
public enum EncoreLogLevel {
case none // No logging (recommended for production)
case debug // Verbose debug logs (development)
}
API keys
Encore supports two types of API keys:
| Key Type | Format | Description |
|---|
| Public API Key | enc_pub... | Production key with standard geo-filtering based on offers’ configured regions |
| Universal Sandbox Key | enc_pub_sandbox... | Testing key that bypasses geo-filtering, allowing you to test the complete entitlement lifecycle from any location |
Use the universal sandbox key (enc_pub_sandbox...) during development to test offers from any location without geo-filtering restrictions. This makes it easy to test the entire entitlement lifecycle end-to-end for a single user.
Always use your production API key (enc_pub...) in production builds. The sandbox key is for development and testing only.
Usage
Basic Configuration
import Encore
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
Encore.shared.configure(apiKey: "pk_your_api_key")
return true
}
SwiftUI
@main
struct YourApp: App {
init() {
Encore.shared.configure(apiKey: "pk_your_api_key")
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
With Debug Logging (Development)
#if DEBUG
Encore.shared.configure(
apiKey: "pk_your_api_key",
logLevel: .debug // Enable debug logs for development
)
#else
Encore.shared.configure(apiKey: "pk_your_api_key") // Silent for production
#endif
Using Universal Sandbox Key for Testing
Use the universal sandbox key to test offers from any location without geo-filtering:
#if DEBUG
Encore.shared.configure(
apiKey: "sb_your_sandbox_key", // Bypasses geo-filtering
logLevel: .debug
)
#else
Encore.shared.configure(apiKey: "pk_your_production_key")
#endif
The universal sandbox key (sb_...) is perfect for comprehensive end-to-end testing of the entitlement lifecycle, allowing you to test location-restricted offers from anywhere during development.
Use logLevel: .debug during development to see detailed SDK logs, then remove it (or use .none) for production builds.