iOS SDK
Swift · iOS 15+ · Xcode 15+
Overview
The Avafli Engagement SDK lets you add daily-entry sweepstakes and prize experiences to your app with a single configuration call. The SDK automatically opens the experience on the first app-open of each day, captures the user, and claims their daily entries — no scheduling or session logic on your side. You customize your logo, prize image, and brand color from the Avafli dashboard; everything else is managed server-side.
Requirements
| iOS | 15.0+ |
| Xcode | 15.0+ |
| Swift | 5.9+ |
| Publisher API Key | Contact info@avafli.com |
Installation
Swift Package Manager (Recommended)
- In Xcode, go to File → Add Package Dependencies
- Enter the repository URL:
https://github.com/AVAFLI/avafli_ios_sdk.git- Select version
3.2.0or later - Add
AvafliSDKto your app target
CocoaPods
Add the pod to your Podfile and run pod install:
pod 'AvafliSDK', '~> 3.0'Quick Start
The simplest integration requires just two calls:
import AvafliSDK
let config = AvafliConfiguration(
apiKey: "YOUR_API_KEY", // debug builds: use your avafli_test_ sandbox key
bundleId: "com.example.myapp",
autoOpen: .always, // or .returningUsersOnly / .never
user: AvafliUser(
id: "user_123", // only id is required — pass whatever identity you have
firstName: "Jane",
lastName: "Doe",
email: "jane@example.com" // include it when you have it — pre-fills & locks the capture form
),
// Nobody signed in? use user: .guest
options: AvafliOptions(
logging: .error, // use .debug while integrating
enablePushReminders: true // streak reminders via YOUR Firebase project
)
)
Avafli.configure(config)
// Done — auto-opens once a day. To open it yourself: Avafli.present()
// Push reminders: forward your FCM token: Avafli.didReceiveFCMToken(token)
By default the experience opens itself on the first app-open of each day — presentation timing, the daily cadence, and dismissal are managed by the SDK. When your app needs to decide the moment, use the controls below.
Controlling when the drawer opens
The default is unchanged: the drawer opens itself once a day on app open. Three controls change that when you need to:
autoOpenon the configuration —.always(default),.returningUsersOnly, or.never..returningUsersOnlykeeps the drawer out of a first-time user's onboarding: it skips the auto-open on the launch where the device is first registered, then auto-opens normally on every later launch..nevermeans the SDK never auto-opens and you callAvafli.present().Avafli.present()— open the drawer from a button, a screen, or an onboarding-complete handler. It ignores the once-a-day rule and the impression cap, waits for registration if it is still in flight, and no-ops if the drawer is already open or the user has opted out. Returnsfalsewhen there is nothing to show; the completion receives theDailyEntryGrantonce today's entry is claimed.Avafli.holdAutoOpen()/Avafli.releaseAutoOpen()— for boot flows. CallAvafli.holdAutoOpen()before configuring to defer the daily auto-open (nothing is burned — no once-a-day mark, no impression), andAvafli.releaseAutoOpen()once your main screen is ready; it re-runs the eligibility check immediately.Avafli.present()still works while held.
let config = AvafliConfiguration(
apiKey: "YOUR_API_KEY",
bundleId: "com.example.myapp",
user: AvafliUser(id: "user_123"),
autoOpen: .never // .always (default) | .returningUsersOnly | .never
)
Avafli.configure(config)
// Later — e.g. from your onboarding-complete handler
func onboardingDidComplete() {
Avafli.present { result in
// .success(grant) once today's entry is claimed; .failure(error) otherwise
}
}Registration and analytics (DAU/MAU) run on configure regardless of mode.
Push Notifications
Drive re-engagement with daily reminders — sent through your own Firebase project. Forward your FCM registration token (and the standard APNs callbacks) to the SDK:
// In your AppDelegate
// MessagingDelegate — server pushes need the FCM token
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let fcmToken { Avafli.didReceiveFCMToken(fcmToken) }
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Avafli.didRegisterForRemoteNotifications(deviceToken: deviceToken)
}Reminders are sent through your own Firebase project — upload your Firebase service account key via the Avafli Dashboard, and forward your FCM registration token with Avafli.didReceiveFCMToken(token). Apps without Firebase Messaging fall back to daily local reminders automatically.
Account deletion in your app
If your app has its own delete-account flow, call optOut() from it so the user's Avafli data is erased along with their account. Users can also delete their data themselves at any time from the Privacy Policy screen inside the experience — no integration required.
// From your delete-account flow
try await Avafli.optOut()Testing? Your dashboard also shows a avafli_test_ sandbox key. Use it in debug builds: identical behavior against the production backend, but users and entries land in an isolated sandbox — your testers can never enter your real giveaway.
SDK Features
Full API Reference & Code Examples
View the complete documentation on GitHub including API reference, code examples, and advanced configuration.