Step 1: Initialize the SDK
Initialize CloudX SDK in yourAppDelegate:
Copy
import UIKit
import CloudXCore
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Initialize CloudX SDK
CloudXCore.shared.initializeSDK(withAppKey: "YOUR_APP_KEY") { error in
if let error = error {
print("CloudX SDK initialization failed: \(error.localizedDescription)")
} else {
print("CloudX SDK initialized successfully")
}
}
return true
}
}
Replace
YOUR_APP_KEY with your actual App Key from the CloudX dashboard at app.cloudx.ioStep 2: Load a Banner Ad
Add a banner ad to your view controller:Copy
import UIKit
import CloudXCore
class ViewController: UIViewController {
private var bannerAdView: CLXBannerAdView?
override func viewDidLoad() {
super.viewDidLoad()
loadBannerAd()
}
private func loadBannerAd() {
// Create banner ad
bannerAdView = CloudXCore.shared.createBanner(
withPlacement: "YOUR_BANNER_PLACEMENT_ID",
viewController: self,
delegate: self,
tmax: 10.0
)
// Add banner to view
if let banner = bannerAdView {
banner.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(banner)
NSLayoutConstraint.activate([
banner.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
banner.centerXAnchor.constraint(equalTo: view.centerXAnchor),
banner.heightAnchor.constraint(equalToConstant: 50),
banner.widthAnchor.constraint(equalToConstant: 320)
])
}
}
}
extension ViewController: CLXBannerDelegate {
func didLoad(with ad: CLXAd) {
print("Banner ad loaded")
}
func failToLoad(with ad: CLXAd, error: Error) {
print("Banner ad failed to load: \(error.localizedDescription)")
}
func didShow(with ad: CLXAd) {
print("Banner ad shown")
}
func didClick(with ad: CLXAd) {
print("Banner ad clicked")
}
}
Step 3: Load an Interstitial Ad
Show full-screen ads between content:Swift
Copy
import UIKit
import CloudXCore
class GameViewController: UIViewController {
private var interstitialAd: CLXInterstitial?
override func viewDidLoad() {
super.viewDidLoad()
loadInterstitial()
}
private func loadInterstitial() {
interstitialAd = CloudXCore.shared.createInterstitial(
withPlacement: "YOUR_INTERSTITIAL_PLACEMENT_ID",
viewController: self,
delegate: self,
tmax: 10.0
)
}
private func showInterstitial() {
if let ad = interstitialAd, ad.isReady() {
ad.show()
} else {
print("Interstitial ad not ready yet")
}
}
}
extension GameViewController: CLXInterstitialDelegate {
func didLoad(with ad: CLXAd) {
print("Interstitial ad loaded and ready to show")
}
func failToLoad(with ad: CLXAd, error: Error) {
print("Interstitial ad failed: \(error.localizedDescription)")
}
func didShow(with ad: CLXAd) {
print("Interstitial ad shown")
}
func failToShow(with ad: CLXAd, error: Error) {
print("Interstitial ad failed to show: \(error.localizedDescription)")
}
func didHide(with ad: CLXAd) {
print("Interstitial ad dismissed")
// Load next ad
loadInterstitial()
}
func didClick(with ad: CLXAd) {
print("Interstitial ad clicked")
}
}
Step 4: Load a Rewarded Ad
Reward users for watching video ads:Swift
Copy
import UIKit
import CloudXCore
class RewardedAdViewController: UIViewController {
private var rewardedAd: CLXRewarded?
override func viewDidLoad() {
super.viewDidLoad()
loadRewardedAd()
}
private func loadRewardedAd() {
rewardedAd = CloudXCore.shared.createRewarded(
withPlacement: "YOUR_REWARDED_PLACEMENT_ID",
viewController: self,
delegate: self,
tmax: 10.0
)
}
private func showRewardedAd() {
if let ad = rewardedAd, ad.isReady() {
ad.show()
} else {
print("Rewarded ad not ready yet")
}
}
}
extension RewardedAdViewController: CLXRewardedDelegate {
func didLoad(with ad: CLXAd) {
print("Rewarded ad loaded and ready to show")
}
func failToLoad(with ad: CLXAd, error: Error) {
print("Rewarded ad failed: \(error.localizedDescription)")
}
func didShow(with ad: CLXAd) {
print("Rewarded ad shown")
}
func failToShow(with ad: CLXAd, error: Error) {
print("Rewarded ad failed to show: \(error.localizedDescription)")
}
func didHide(with ad: CLXAd) {
print("Rewarded ad dismissed")
}
func didClick(with ad: CLXAd) {
print("Rewarded ad clicked")
}
func didReward(with ad: CLXAd) {
print("User earned reward!")
// Grant reward to user
}
}
Step 5: Test Your Integration
Use test placement IDs during development:Test Placements
Copy
// Test App Key
let testAppKey = "test-app-key-ios"
// Test Placement IDs
let testBannerPlacement = "test-banner-ios"
let testInterstitialPlacement = "test-interstitial-ios"
let testRewardedPlacement = "test-rewarded-ios"
Always use test placement IDs during development to avoid policy violations
MREC (Medium Rectangle) Ads
Load 300x250 ads for better revenue:Swift
Copy
import CloudXCore
class MRECViewController: UIViewController {
private var mrecAdView: CLXBannerAdView?
override func viewDidLoad() {
super.viewDidLoad()
loadMREC()
}
private func loadMREC() {
// MREC is created using createBanner with 300x250 size
mrecAdView = CloudXCore.shared.createBanner(
withPlacement: "YOUR_MREC_PLACEMENT_ID",
viewController: self,
delegate: self,
tmax: 10.0
)
if let mrec = mrecAdView {
mrec.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(mrec)
NSLayoutConstraint.activate([
mrec.centerXAnchor.constraint(equalTo: view.centerXAnchor),
mrec.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20),
mrec.heightAnchor.constraint(equalToConstant: 250),
mrec.widthAnchor.constraint(equalToConstant: 300)
])
}
}
}
extension MRECViewController: CLXBannerDelegate {
func didLoad(with ad: CLXAd) {
print("MREC ad loaded")
}
func failToLoad(with ad: CLXAd, error: Error) {
print("MREC ad failed: \(error.localizedDescription)")
}
}
SwiftUI Support
CloudX SDK works with SwiftUI using UIViewRepresentable:ContentView.swift
Copy
import SwiftUI
import CloudXCore
struct ContentView: View {
var body: some View {
VStack {
Text("My App")
.font(.title)
.padding()
Spacer()
BannerAdView(placementID: "YOUR_BANNER_PLACEMENT_ID")
.frame(width: 320, height: 50)
}
}
}
struct BannerAdView: UIViewRepresentable {
let placementID: String
func makeUIView(context: Context) -> CLXBannerAdView {
guard let viewController = UIApplication.shared.windows.first?.rootViewController else {
return CLXBannerAdView()
}
let banner = CloudXCore.shared.createBanner(
withPlacement: placementID,
viewController: viewController,
delegate: context.coordinator,
tmax: 10.0
)
return banner ?? CLXBannerAdView()
}
func updateUIView(_ uiView: CLXBannerAdView, context: Context) {}
func makeCoordinator() -> Coordinator {
Coordinator()
}
class Coordinator: NSObject, CLXBannerDelegate {
func didLoad(with ad: CLXAd) {
print("Banner ad loaded in SwiftUI")
}
func failToLoad(with ad: CLXAd, error: Error) {
print("Banner ad failed in SwiftUI: \(error.localizedDescription)")
}
func didShow(with ad: CLXAd) {}
func didClick(with ad: CLXAd) {}
}
}
Next Steps
Common Issues
SDK initialization fails
SDK initialization fails
- Verify your App Key is correct
- Check internet connectivity
- Ensure Info.plist is configured properly with
GADApplicationIdentifier - Make sure you’re calling
initializeSDKbefore creating any ads
Ads not loading
Ads not loading
- Use test placement IDs during development
- Check placement IDs are correct in CloudX dashboard
- Request ATT permission (iOS 14+) before loading ads
- Verify network connectivity
- Check console logs for error messages
Build errors
Build errors
- Clean build folder (Cmd+Shift+K)
- Update to latest Xcode version (14.0+)
- Check minimum deployment target (iOS 14.0+)
- Verify CloudXCore framework is properly linked
- For SPM: Try resetting package cache
Banner not visible
Banner not visible
- Ensure banner is added to view hierarchy
- Check frame/constraints are set correctly
- Banner size should be 320x50 for standard banner, 300x250 for MREC
- Make sure
didLoadcallback is called