Live Q&A (Beta)
This guide shows how to add Viafoura Live Q&A to an iOS app using VFLiveQuestionsViewController.
Requirements
- The app includes
ViafouraSDK. - The SDK is initialized before presenting any Viafoura UI.
- You have a Live Q&A
containerIdfor the page, event, or content surface. - The presenting view controller implements
VFLoginDelegate.
1. Implement Login Handling
Live Q&A can be viewed anonymously, but posting, replying, liking, and moderation actions require authentication. The SDK calls startLogin() when the user tries an authenticated action while logged out.
import UIKit
import ViafouraSDK
final class ArticleViewController: UIViewController, VFLoginDelegate {
func startLogin() {
let loginViewController = LoginViewController()
present(loginViewController, animated: true)
}
}After your login flow completes, authenticate the user with the Viafoura auth service. Use the auth method that matches your integration.
Task {
do {
try await ViafouraSDK.auth().cookieLogin(token: viafouraCookieToken)
} catch {
// Show your login error state.
}
}Other supported auth methods include login(email:password:), openIdLogin(token:), socialLogin(token:provider:), and loginRadiusLogin(token:provider:).
2. Build Article Metadata
Live Q&A posts include article metadata for analytics, moderation context, and profile/history surfaces.
let articleMetadata = VFArticleMetadata(
url: URL(string: "https://example.com/articles/live-qa")!,
title: "Live Q&A",
subtitle: "Ask questions during the live event",
thumbnailUrl: URL(string: "https://example.com/images/live-qa.jpg")!
)3. Create the Live Q&A View Controller
Use VFLiveQuestionsViewController.new(...).
let settings = VFSettings(colors: VFColors())
let liveQuestionsViewController = VFLiveQuestionsViewController.new(
containerId: "YOUR_LIVE_QA_CONTAINER_ID",
articleMetadata: articleMetadata,
loginDelegate: self,
settings: settings
)Optional parameters:
let liveQuestionsViewController = VFLiveQuestionsViewController.new(
containerId: "YOUR_LIVE_QA_CONTAINER_ID",
articleMetadata: articleMetadata,
loginDelegate: self,
settings: settings,
sectionUUID: UUID(uuidString: "YOUR_SECTION_UUID")!,
limit: 20,
replyLimit: 2
)containerId: your external Live Q&A container id.articleMetadata: metadata for the page or event.loginDelegate: the object that starts login when needed.settings: Viafoura colors, fonts, and theme settings.sectionUUID: optional. If omitted, the SDK usesViafouraSDK.siteUUID.limit: number of top-level questions loaded per page.replyLimit: number of replies loaded with each question.
4. Handle SDK Actions
Set action callbacks if your app needs to respond to profile taps or other SDK actions.
let callbacks: VFActionsCallbacks = { [weak self] action in
guard let self else { return }
switch action {
case .openProfilePressed(let userUUID, let presentationType):
let profileViewController = VFProfileViewController.new(
userUUID: userUUID,
presentationType: presentationType,
loginDelegate: self,
settings: settings
)
self.present(profileViewController, animated: true)
default:
break
}
}
liveQuestionsViewController.setActionCallbacks(callbacks: callbacks)5. Apply Theme
If your app supports light and dark mode, set the SDK theme before presentation.
let theme: VFTheme = traitCollection.userInterfaceStyle == .dark ? .dark : .light
liveQuestionsViewController.setTheme(theme: theme)6. Present Live Q&A
The recommended integration is to push Live Q&A in a navigation stack.
liveQuestionsViewController.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(liveQuestionsViewController, animated: true)You can also present it modally inside a navigation controller.
let navigationController = UINavigationController(rootViewController: liveQuestionsViewController)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true)Complete Example
import UIKit
import ViafouraSDK
final class ArticleViewController: UIViewController, VFLoginDelegate {
private let liveQAContainerId = "YOUR_LIVE_QA_CONTAINER_ID"
func showLiveQA() {
let settings = VFSettings(colors: VFColors())
let metadata = VFArticleMetadata(
url: URL(string: "https://example.com/articles/live-qa")!,
title: "Live Q&A",
subtitle: "Ask questions during the live event",
thumbnailUrl: URL(string: "https://example.com/images/live-qa.jpg")!
)
let liveQA = VFLiveQuestionsViewController.new(
containerId: liveQAContainerId,
articleMetadata: metadata,
loginDelegate: self,
settings: settings
)
let callbacks: VFActionsCallbacks = { [weak self] action in
guard let self else { return }
switch action {
case .openProfilePressed(let userUUID, let presentationType):
let profile = VFProfileViewController.new(
userUUID: userUUID,
presentationType: presentationType,
loginDelegate: self,
settings: settings
)
self.present(profile, animated: true)
default:
break
}
}
liveQA.setActionCallbacks(callbacks: callbacks)
liveQA.setTheme(theme: traitCollection.userInterfaceStyle == .dark ? .dark : .light)
liveQA.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(liveQA, animated: true)
}
func startLogin() {
let loginViewController = LoginViewController()
present(loginViewController, animated: true)
}
}Updated about 3 hours ago
