Installation
Add the package in Xcode via File → Add Package Dependencies:Package.swift:
How the pieces fit together
1
Initialize the client
Create a
Gravity instance with your API key and production: true.2
Collect context & fetch ads
Call
gravity.getAds(...) with the conversation messages, session ID, and placements. The SDK auto-collects device signals (UA, OS, screen, timezone). Run it in parallel with your LLM call.3
Render
Use the built-in
GravityAdView (SwiftUI) or render the ad data yourself. Impression tracking fires automatically on appear.Quick start
Constructor
getAds()
device forwarding needed.
Placements
SwiftUI — render ads
SpecAdView automatically handles the Gravity-managed placement design, safe fallback, impression and click tracking, required ad disclosure, and server-requested feedback controls.
Custom rendering
If you render ads with your own UI, fire tracking manually:PII hashing
Hash email and phone for attribution without sending raw values:Ad feedback
Full example — parallel with LLM stream
FAQ
Does the ad request block my LLM response?
Does the ad request block my LLM response?
No. Use
async let to fire getAds() in parallel with your LLM call. It never throws, so failures are silent.Does the SDK collect IDFA?
Does the SDK collect IDFA?
No. The SDK does not access the Advertising Identifier. If you have IDFA consent via ATT, pass it as
extraDeviceFields: ["ifa": idfa].What iOS versions are supported?
What iOS versions are supported?
iOS 15+, macOS 12+, tvOS 15+, watchOS 8+.
Does the SDK add any third-party dependencies?
Does the SDK add any third-party dependencies?
No. It uses only Foundation, CryptoKit, and URLSession — all built into the platform.

