Rewarded Ads
Rewarded ads are advertisements that users can choose to watch in exchange for a reward, such as in-app currency, extra lives, or premium content. They are typically offered at natural points in an app, like after completing a level or task, allowing users to earn benefits while engaging with the ad.
Create BoldwinRewarded
To create a rewarded ad, start by initializing a BoldwinRewarded with the following parameter:
- placementID - A string used to identify the ad placement
Ad Sizes
A single ad unit can be configured to support multiple ad sizes:
Note: By setting this property you replace the ad sizes specified during initialization.
If ad sizes are not specified, the SDK automatically determines the optimal sizes for the device.
SKOverlay
By default, BoldwinRewarded enables SKOverlay, allowing ads to leverage Apple's SKOverlay functionality. If needed, developers can disable this feature by setting the supportSKOverlay flag to false, which prevents the rewarded ads from using SKOverlay.
Ad Events
You can optionally assign a delegate to receive callbacks for ad events:
// MARK: - BoldwinRewardedDelegate
extension RewardedViewController: BoldwinRewardedDelegate {
func rewardedAdDidReceiveAd(
_ rewardedAd: BoldwinRewarded,
ad: BoldwinAd
) {
// Called when ad is loaded.
}
func rewardedAd(
_ rewardedAd: BoldwinRewarded,
didFailToReceiveAdWithError error: BoldwinError?
) {
// Called when Boldwin SDK failed to load ad.
print("Did fail to receive ad with error: \(String(describing: error?.localizedDescription))")
}
func rewardedAdUserDidEarnReward(
_ rewardedAd: BoldwinRewarded,
reward: BoldwinReward
) {
// Called when the reward was granted to user
}
func rewardedAdWillPresentAd(_ rewardedAd: BoldwinRewarded) {
// Called when rewarded ad is about to be presented.
}
func rewardedAdDidDismissAd(_ rewardedAd: BoldwinRewarded) {
// Called when rewarded ad is dismissed.
}
func rewardedAdDidClickAd(_ rewardedAd: BoldwinRewarded) {
// Called when rewarded ad was clicked.
}
func rewardedAdWillLeaveApplication(_ rewardedAd: BoldwinRewarded) {
// Called when the application is about to enter the background.
}
}
Ad Metadata
You can access the information about the loaded ad in rewardedAdDidReceiveAd delegate method. View the details here: BoldwinAd.
Load Ad
Once BoldwinRewarded is configured, start loading the ad:
Display the Ad
To display a rewarded ad, verify that it is ready using the isReady property, and then present it by calling show(from:):
See the complete integration example below:
import Boldwin
class RewardedViewController: UIViewController {
private var boldwinRewarded: BoldwinRewarded?
override func viewDidLoad() {
super.viewDidLoad()
createAd()
}
private func createAd() {
// 1. Create BoldwinRewarded instance.
let rewarded = BoldwinRewarded(
placementID: placementID
)
// 2. Optionally set delegate.
rewarded.delegate = self
// Store instance.
self.boldwinRewarded = rewarded
// 3. Load the ad.
rewarded.loadAd()
}
@IBAction func showRewardedVideo() {
// 4. Check if the ad is ready to be displayed.
if boldwinRewarded?.isReady == true {
// 5. Show the ad.
boldwinRewarded?.show(from: self)
}
}
}
// MARK: - BoldwinRewardedDelegate
extension RewardedViewController: BoldwinRewardedDelegate {
func rewardedAdDidReceiveAd(
_ rewardedAd: BoldwinRewarded,
ad: BoldwinAd
) {
// Called when ad is loaded.
}
func rewardedAd(
_ rewardedAd: BoldwinRewarded,
didFailToReceiveAdWithError error: BoldwinError?
) {
// Called when Boldwin SDK failed to load ad.
print("Did fail to receive ad with error: \(String(describing: error?.localizedDescription))")
}
func rewardedAdUserDidEarnReward(
_ rewardedAd: BoldwinRewarded,
reward: BoldwinReward
) {
// Called when the reward was granted to user
}
func rewardedAdWillPresentAd(_ rewardedAd: BoldwinRewarded) {
// Called when rewarded ad is about to be presented.
}
func rewardedAdDidDismissAd(_ rewardedAd: BoldwinRewarded) {
// Called when rewarded ad is dismissed.
}
func rewardedAdDidClickAd(_ rewardedAd: BoldwinRewarded) {
// Called when rewarded ad was clicked.
}
func rewardedAdWillLeaveApplication(_ rewardedAd: BoldwinRewarded) {
// Called when the application is about to enter the background.
}
}