import MpwaAds
import UIKit
class RewardedFlow: NSObject, RewardedVideoAdDelegate {
private let ad: RewardedVideoAd
init(adUnitId: UInt64) {
// The ad-unit ID comes from /dashboard/apps → your app → ad units.
self.ad = RewardedVideoAd(adUnitId: adUnitId)
super.init()
self.ad.delegate = self
}
func loadAndShow(from vc: UIViewController) {
Task {
do {
try await ad.load()
ad.show(from: vc)
} catch {
print("rewarded load failed: \(error)")
}
}
}
// MARK: RewardedVideoAdDelegate
func rewardedVideo(_ ad: RewardedVideoAd, didReward reward: Reward) {
// Credit reward.amount of reward.currency to the user. Server-side
// verification happens automatically — your SSV callback (set in
// /dashboard/settings → Rewarded SSV) gets a signed POST in parallel.
print("granted \(reward.amount) \(reward.currency) for impression \(reward.impressionId)")
}
func rewardedVideoDidDismiss(_ ad: RewardedVideoAd) {
print("user closed without completing")
}
}
Set the SSV callback URL on /dashboard/settings → Rewarded SSV before going live. Without it the SDK still grants, but you have no server-side signal to credit the user authoritatively.