Choose the version rule (e.g. “Up to Next Major” starting from 0.1.1) and add the package.
4
Add to Target
Add the VelocityAdsSDK library to your app target.
The package uses a binary target hosted on GitHub Releases. Each release (e.g. 0.1.1) provides a pre-built XCFramework; Xcode resolves the correct asset automatically when you select a version.
The SDK provides a method for loading native ads:loadNativeAd(prompt:aiResponse:conversationHistory:dimensions:adUnitId:callback:) - Returns ad data model via callback (NativeAd)
VelocityAds.loadNativeAd( prompt: "What's the weather today?", aiResponse: "The weather is sunny with 72°F...", // Optional: provide AI response for better targeting conversationHistory: nil, // Optional: conversation history for better targeting dimensions: AdDimensions(width: 320, height: 50), // Always provide ad dimensions in points adUnitId: "ad_unit_123", // Optional callback: self)// AdCallback implementationfunc onSuccess(nativeAd: NativeAd) { // Display ad manually titleLabel.text = nativeAd.title descriptionLabel.text = nativeAd.description ctaButton.setTitle(nativeAd.callToAction, for: .normal) // Load image (e.g. with URLSession or a library like SDWebImage) loadImage(from: nativeAd.imageUrl, into: adImageView) // Handle click ctaButton.addAction(UIAction { [weak self] _ in if let url = URL(string: nativeAd.clickUrl) { UIApplication.shared.open(url) } }, for: .touchUpInside) // Track impression trackImpression(nativeAd.impressionUrl)}func onError(error: String) { print("Failed to load ad: \(error)")}
For better ad targeting in chat applications, you can provide conversation history.The conversationHistory parameter accepts an array of dictionaries ([[String: Any]]?). Each dictionary should have:
"role" ("user" or "assistant")
"content" (message text)
Pass nil on the first call, then include the accumulated history on subsequent calls:
// First call - no conversation historyVelocityAds.loadNativeAd( prompt: "What's the weather today?", aiResponse: "The weather is sunny...", conversationHistory: nil, dimensions: AdDimensions(width: 320, height: 50), callback: adCallback)// Subsequent calls - with conversation historylet conversationHistory: [[String: Any]] = [ ["role": "user", "content": "What's the weather today?"], ["role": "assistant", "content": "The weather is sunny..."]]VelocityAds.loadNativeAd( prompt: "What about tomorrow?", aiResponse: "Tomorrow will be cloudy...", conversationHistory: conversationHistory, dimensions: AdDimensions(width: 320, height: 50), callback: adCallback)
Update the conversation history with the full conversation for best targeting.
If your app serves users in the European Economic Area (EEA), UK, or other regions where GDPR applies, you must obtain user consent before processing their personal data.Method:VelocityAds.setConsent(_:)Parameters:
consent (Bool) - true if the user gives consent for data processing, false if the user denies consent
// User gives consent (GDPR)VelocityAds.setConsent(true)// User denies consentVelocityAds.setConsent(false)
Geography-Specific: Only call this API in regions where GDPR regulations apply.
If your app serves users in regions where CCPA applies, you must provide a way for users to opt out of the sale of their personal information.Method:VelocityAds.setDoNotSell(_:)Parameters:
doNotSell (Bool) - true if the user opts out of the sale of personal information, false if the user allows data sharing
// User opts out of data sale (CCPA)VelocityAds.setDoNotSell(true)// User allows data sharingVelocityAds.setDoNotSell(false)
Geography-Specific: Only call this API in regions where CCPA regulations apply.
On iOS, access to IDFA is controlled by App Tracking Transparency (ATT). Your app must request tracking authorization when appropriate; the SDK uses the advertising identifier only when the user has granted permission.
The SDK does not perform cross-app tracking; the host app controls ATT and the SDK uses identifiers for ad delivery and analytics within your app.
The Velocity Ads SDK uses IDFA (Identifier for Advertisers) and IDFV (Identifier for Vendor) when available to improve ad performance and relevance. These identifiers enable:
Better ad targeting - More relevant ads for your users