-
Notifications
You must be signed in to change notification settings - Fork 0
Initialize CAS
To begin, create a string constant with your casID
. This constant will be needed when creating each ad format instance.
What is CAS ID?
In most cases, a CASID is the same as your app store ID.
You can find an app store ID in the URL of your app’s Apple App Store URL. For example, the URL is apps.apple.com/us/app/id123456789
then app store ID is 123456789
.
If you haven't created an CAS account and registered an app yet, now's a great time to do so at https://cas.ai
If you just want to experiment or test the SDK, you can skip the configuration your project.
import CleverAdsSolutions
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
static let casID: String = "123456789"
var window: UIWindow? // required for some mediated ads frameworks
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
initializeCAS()
return true
}
...
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
...
}
You can skip the manual call for ad initialization, and then the SDK will automatically perform the initialization before the first ad load. However, if it's important for you to change the configuration or listen to states of the Consent Flow, make sure to initialize it at least once before the first ad load.
func initializeCAS() {
let builder = CAS.buildManager()
builder.withCompletionHandler { config in
// The CAS SDK initializes if the error is `nil`
let error: String? = config.error
let userCountryISO2: String? = config.countryCode
// True if the user is protected by GDPR or other regulations
let protectionApplied: Bool = config.isConsentRequired
// The user completes the consent flow
let consentStatus = config.consentFlowStatus
let trackingAuthorized: Bool = config.isATTrackingAuthorized
}
builder.create(withCasId: casID)
}
The withCompletionHandler
may be called with an error. In this case, the SDK will attempt to reinitialize and the listener will be called again until the error is resolved.
Important
Do not initialize mediated advertising SDKs (CAS does that for you).
Not following this step will result in noticeable integration issues.
To handle app delegate callbacks in an app that uses the SwiftUI lifecycle, you must create an application delegate and attach it to your App
struct using UIApplicationDelegateAdaptor
.
@main
struct YourApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
}
}
}
Use the CleverAdsSolutions module import. All classes have the CAS
prefix and use the same names as in Swift.
@import CleverAdsSolutions;
To get consent for collecting personal data of your users, we suggest you use a built-in Consent Flow, comes with a pre-made consent form that you can easily present to your users. That means you no longer need to create your own consent window.
The user will see the consent flow when your app initialize CAS SDK. When the user completes the flow, the SDK calls your initialization-completion handler.
CAS consent flow is enabled by default. You can disable the consent flow by add disabled CASConsentFlow
to withConsentFlow()
:
builder.withConsentFlow(
CASConsentFlow(isEnabled: false)
)
Make sure to apply all configurations before calling builder.build()
.
You must wait until the user finishes the consent flow before you initialize third-party SDKs (such as MMPs or analytics SDKs). For this reason, initialize such SDKs from within your initialization-completion callback. If you were to initialize these third-party SDKs before the user completes the consent flow, these third-party SDKs would not be able to access relevant identifiers and you would suffer a material impact on measurement, reporting, and ad revenue.
Note
Read more about "Privacy options button" and "Debug geography" on CAS User Consent Flow page
When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.
By default, CAS initializes mediation in live mode. To enable test ad mode, you should manually call initializeCAS()
with the following option:
#if DEBUG
builder.withTestAdMode(true)
#endif
For more information about how the CAS.AI SDK's test ads work, see Enable test ads
We are not removing support for managing ads using CASMediationManager
at this time, but we recommend migrating to the new CASInterstitial
and CASRewarded
components whenever possible.
To continue using MediationManager
, you still need to specify the ad formats you want to work with, just as before.
builder.withAdTypes(CASType.interstitial, CASType.rewarded)
If your app no longer uses CASMediationManager
for Interstitial and Rewarded formats, simply do not define any formats during initialization.
To programmatically retrieve the SDK version number at runtime, CAS provides the following method:
String sdkVersion = CAS.getSDKVersion();
Set the time interval during which users can enjoy an ad-free experience while retaining access to Rewarded Ads and App Open Ads formats. This interval is defined from the moment of the initial app installation, in seconds. Within this interval, users enjoy privileged access to the application's features without intrusive advertisements.
let secondsIn7Days = 604800
CAS.settings.trialAdFreeInterval = secondsIn7Days
🔗 Next
Privacy Regulations
- Integration
- Initialization
- Additional mediation steps
- AppStore data disclosure
- App-ads.txt🔗
- App Open Ad
- Banner Ad
- Interstitial Ad
- Rewarded Ad
- Native Ad