Skip to main content

“SDK not initialized” Error

Problem: Calling loadNativeAd before initSDK, or loading ads before initialization has completed.

Solution 1 — Use InitCallback

Initialize at startup and only load ads after initialization succeeds. This avoids calling loadNativeAd before the SDK is ready.
VelocityAds.initSDK(
    appKey: "YOUR_APPLICATION_KEY",
    callback: MyInitCallback()
)

class MyInitCallback: InitCallback {
    func onInitSuccess(sessionId: String, mediationEnabled: Bool) {
        // SDK is ready — enable ad loading in your UI or trigger first ad load
        enableAdLoading()
    }

    func onInitFailure(error: String) {
        // Handle failure (e.g. show message, disable ad features)
        print("SDK init failed: \(error)")
    }
}

Solution 2 - Check before loading

Before ad loading, ensure the SDK is initialized and init if needed.
// When you're about to load an ad (e.g. in response to user action):
guard VelocityAds.isInitialized() else {
    // SDK not ready — init was not called, failed, or hasn't completed yet.
    return  // Skip this ad load, or retry later when initialized
}

VelocityAds.loadNativeAd(
    prompt: prompt,
    aiResponse: aiResponse,
    conversationHistory: conversationHistory,
    dimensions: dimensions,
    adUnitId: adUnitId,
    callback: self
)

Ads Not Loading

Checklist:
  • ✅ SDK initialized at app startup (AppDelegate or App init)
  • ✅ Network connectivity available
  • ✅ Debug mode enabled to see logs

Enable Debug Mode

VelocityAds.initSDK(
    appKey: "YOUR_APPLICATION_KEY",
    debug = true  // Enable debug logs
)

Memory / Lifecycle

Problem: Using a callback that is deallocated before the callback runs (e.g. a cell that is reused). Solution: Retain the callback (e.g. in a dedicated object or via the view controller) until onSuccess or onError is called. Avoid using self from a short-lived object (e.g. table view cell) as the callback without retaining it.

No Ads Returned

Possible causes:
  • No ads available for the given context
  • Network issues
  • Ad unit not configured
Solution: Handle onError gracefully (e.g. hide ad space or show fallback). The SDK continues to function even when no ads are available.