Rewarded
Integration
Just as interstitials, rewarded ads can only be integrated with code. Below we show a simple example to understand how it works:
import UIKit
import WortiseSDK
class ViewController: UIViewController {
private var rewardedAd: WARewardedAd!
override func viewDidLoad() {
super.viewDidLoad()
...
rewardedAd = WARewardedAd(adUnitId: "test-rewarded")
rewardedAd.loadAd()
}
override func willMove(toParent controller: UIViewController?) {
super.willMove(toParent: controller)
...
rewardedAd.destroy()
}
func showRewarded() {
if rewardedAd.isAvailable {
rewardedAd.showAd(from: self)
}
}
}
Delegate configuration
Like occurs with other formats, a listener can be set to receive the events that happen during the rewarded lifecycle. For this, it is needed to implement the WARewardedDelegate
interface just as shown in the example below:
extension ViewController : WARewardedDelegate {
func didClick(rewardedAd: WARewardedAd) {
// Invoked when the ad has been clicked
}
func didComplete(rewardedAd: WARewardedAd, reward: WAReward) {
// Invoked when the ad has been completed
}
func didDismiss(rewardedAd: WARewardedAd) {
// Invoked when the ad has been dismissed
}
func didFailToLoad(rewardedAd: WARewardedAd, error: WAAdError) {
// Invoked when the ad could not be loaded
// (because of an error or no fill)
}
func didFailToShow(rewardedAd: WARewardedAd, error: WAAdError) {
// Invoked when the ad could not be shown
}
func didImpress(rewardedAd: WARewardedAd) {
// Invoked when the ad has generated an impression
}
func didLoad(rewardedAd: WARewardedAd) {
// Invoked when the ad has been loaded
}
func didPayRevenue(rewardedAd: WARewardedAd, data: WARevenuedata) {
// Invoked when the ad has generated revenue
}
func didShow(rewardedAd: WARewardedAd) {
// Invoked when the ad has been shown
}
}
Once the interface is implemented, the delegate is assigned to the ad instance:
rewardedAd.delegate = self
Última actualización