Skip to Content
Swift SDKGuidesCampaign Lifecycle

Campaign Lifecycle

Everything is configured in the Vio Dashboard — the SDK discovers campaigns automatically at runtime. No campaign IDs in your app code.

How It Works

Dashboard SDK ───────── ─── Broadcast setBroadcastContext(broadcastId) └── externalId → discoverCampaigns(broadcastId) └── Campaign ├── currentCampaign set ├── Polls ├── WebSocket /ws/:campaignId connected ├── Contests ├── Polls received via WS └── Sponsor └── Sponsor assets applied

Setup: autoDiscover: true

Use this in your vio-config.json — no hardcoded campaign IDs:

{ "apiKey": "YOUR_API_KEY", "campaigns": { "webSocketBaseURL": "wss://api.vio.live", "restAPIBaseURL": "https://api.vio.live", "campaignApiKey": "YOUR_CAMPAIGN_API_KEY", "autoDiscover": true } }

Connect to a Broadcast

Call setBroadcastContext with the broadcast’s externalId as configured in the Dashboard:

import VioCore // When user opens a stream let context = BroadcastContext( broadcastId: "real-madrid-vs-barcelona-2025-01-24", // = externalId in Dashboard broadcastName: "Real Madrid vs Barcelona" ) await CampaignManager.shared.setBroadcastContext(context)

This triggers:

  1. API call to GET /v1/sdk/broadcast?contentId=<broadcastId> — finds the campaign
  2. WebSocket connects to /ws/:campaignId
  3. Backend sends the current state (active polls, contests) immediately
  4. Real-time events flow in as you scheduled them in the Dashboard

Disconnect

// When user closes the stream CampaignManager.shared.disconnect()

Campaign States

StateWhenBehavior
ActiveBetween campaign start/end dates, broadcast is liveComponents shown, WS connected
UpcomingBefore campaign start datecampaignState = .upcoming
EndedAfter campaign end dateComponents hidden, WS disconnected
PausedDashboard manually pausedisPaused = true, components hidden
// Check state in your UI switch CampaignManager.shared.campaignState { case .active: // Show overlay case .upcoming: Text("Starting soon") case .ended: // Hide overlay } let isActive = CampaignManager.shared.isCampaignActive

Multiple Broadcasts

If you have multiple streams running, each call to setBroadcastContext resets to a fresh state for the new broadcast — previous polls and contests are cleared automatically.

WebSocket Events

The SDK handles these automatically:

EventEffect
pollPoll added/updated in EngagementManager
contestContest added/updated
shoppable_adProduct overlay triggered
campaign_startedCampaign activated
campaign_endedComponents hidden, WS closed
tweetTweet card added to timeline
chat_messageChat message received

Next Steps

Last updated on