iOS – Configuring
Learn how to import Adapty iOS SDK in your app, configure it, and set up logging
In your AppDelegate
class:
import Adapty
And add the following to application(_:didFinishLaunchingWithOptions:)
:
Adapty.activate("PUBLIC_SDK_KEY", customerUserId: "YOUR_USER_ID")
- Public SDK key (required): found in your app settings in Adapty Dashboard App settings > General.
- Observer mode (optional): a boolean value controlling Observer mode. Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics.
- Customer user ID (optional): an identifier of the user in your system. We send it in subscription and analytical events, to attribute events to the right profile. You can also find customers by
customerUserId
in the Profiles section.
If you don't have a user ID at the time of Adapty initialization, you can set it later using.identify()
method. Read more in the Identifying Users section. - Enable Usage Logs (default value
false
): a boolean value which can enable the feature of collecting logs with at servers. Read more in the Collecting Usage Logs section. - StoreKit 2 Usage (default value
.disabled
): a value which controls StoreKit 1 and 2 API utilisation. Read more in the Displaying Paywalls & Products section.
Note that
storeKit2Usage
refers to the method the SDK uses to determine eligibility for introductory offers, not the payment process itself. Pass the value.forIntroEligibilityCheck
if you want to utilize the StoreKit 2 API for this specific purpose.Note, that StoreKit 2 is available since iOS 15.0. Adapty will implement the legacy logic for older versions.
Make sure you use the Public SDK key for Adapty initialization, the Secret key should be used for server-side API only.
SDK keys are unique for every app, so if you have multiple apps make sure you choose the right one.
Logging system
Adapty logs errors and other important information to help you understand what is going on. There are four levels available:
.error
: only errors will be logged.warn
: messages from the SDK that do not cause critical errors, but are worth paying attention to.info
: various information messages, such as those that log the lifecycle of various modules.verbose
: any additional information that may be useful during debugging, such as function calls, API queries, etc.
You can set logLevel
at any time in the application's lifespan, but we recommend that you do this before configuring Adapty.
Adapty.logLevel = .verbose
Overriding logger handler
If you for some reason need to send messages from Adapty to your system or save them to a file, you can override the default behavior:
Adapty.setLogHandler { level, message in
writeToLocalFile("Adapty \(level): \(message)")
}
Collecting usage logs
The Adapty SDK allows you to activate the remote logging system. If you are experiencing any problems during a review process, or you need help with analyzing something in the production environment, you will need to activate this system both in the application's build itself and in our system (Contact the technical support team for the assistance).
To activate this system, pass the enableUsageLogs
parameter while activating the SDK:
Adapty.activate("PUBLIC_SDK_KEY", enableUsageLogs: true)
Updated 2 months ago