Getting Started
🚀 SDK Initialization
Before loading any ads, you must initialize the SDK. There are two initialization methods available:
✅ Option 1: initialize(with: config) – Local Config
Use this if you want full control and local inline config via code.
In your ViewController (or any UIViewController where you want to display ads):
- Import the SDK
- Initialize with a local configuration
import OCMAdNetworkIOS
Task {
do {
let config = OcmConfigBuilder()
.adUnit(
id: "1001-sreq-test-300x250-imp-1",
format: "banner",
size: "300x250"
)
.gam(
networkCode: "75351959",
adUnitPath: "/75351959/testadunit/test_app_320x50"
)
.privacyFromSdk(
gdpr: gdpr ? 1 : 0,
ccpa: "",
coppa: 0
)
.build()
try await OcmAdNetworkSDK.initialize(with: config)
print("✅ SDK initialized")
} catch {
print("❌ SDK init failed: \(error.localizedDescription)")
}
}
✅ Option 2: initialize() – With Publisher ID
Use this if your config is stored remotely or retrieved from backend.
import OCMAdNetworkIOS
Task {
do {
try await OcmAdNetworkSDK.initialize(publisherId: "test_pub_001")
print("✅ SDK initialized")
} catch {
print("❌ SDK init failed: \(error.localizedDescription)")
}
}
Quick Start Example
Here's a minimal example to get you started:
import UIKit
import OCMAdNetworkIOS
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Task {
do {
try await OcmAdNetworkSDK.initialize(publisherId: "test_pub_001")
print("✅ SDK initialized and ready to load ads")
} catch {
print("❌ SDK init failed: \(error.localizedDescription)")
}
}
}
}
Next Steps
- Learn about Configuration options
- Explore the API Reference to load ads
- Check out complete Examples