Swift
Rewarded
Rewarded is an ad shown in full-screen video, with the option to close it appear when the video is completed . Add the following lines to the ViewController.swift file: Example:
import UIKit
class ViewController: UIViewController {
var rewardedAd: TappxRewardedViewController? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func showRewardedClick(_ sender: Any) {
rewardedAd = TappxRewardedViewController(delegate: self)
rewardedAd?.setAutoShowWhenReady(true)
rewardedAd?.load()
}
}
extension ViewController: TappxRewardedViewControllerDelegate {
func present(_ viewController: UIViewController{
self.present(viewController, animated: true, completion: nil)
}
func presentViewController() -> UIViewController {
return self
}
}
If you want to request a rewarded to be shown as soon as it's ready, you can use this method:
rewardedAd?.setAutoShowWhenReady(true)
If you want to have more control, you can use the following three options: load, isReady, show, setPopupMessage and setCountDownMessage.
load is the request to get the ad and load all the information so you can show the ad.
rewardedAd?.load()
isReady allows you to check if the ad is ready to be shown. You will receive a "true" if the ad is ready and a "false" if not.
rewardedAd?.isReady
show allows you to display the rewarded ad that has loaded previously.
rewardedAd?.show()
setPopupMessage allows you to configure text messages in the Pop-Up.
rewardedAd?.setPopupMessage(message: "Text Message", accept:"Text Button Accept", cancel:"Text Button Cancel");
setCountDownMessage allows you to configure text messages in the Countdown.
rewardedAd?.setCountDownMessage(beforeCountDown:"Text Before Numbers", afterCountrDown:"Text After Second Numbers");
Delegates
You can add listener events into the rewarded to be notified when a specific event happens in the ad. Here you have examples:
extension ViewController: TappxRewardedViewControllerDelegate {
func tappxRewardedViewControllerDidFinishLoad(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerDidFinishLoad")
}
func tappxRewardedViewControllerClicked(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerClicked")
}
func tappxRewardedViewControllerDismissed(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerDismissed")
}
func tappxRewardedViewControllerDidAppear(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerDidAppear")
}
func tappxRewardedViewControllerVideoClosed(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerVideoClosed")
}
func tappxRewardedViewControllerPlaybackFailed(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerPlaybackFailed")
}
func tappxRewardedViewControllerVideoCompleted(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerVideoCompleted")
}
func tappxRewardedViewControllerUserDidEarnReward(_ viewController: TappxRewardedViewController) {
debugPrint("tappxRewardedViewControllerUserDidEarnReward")
}
func tappxRewardedViewControllerDidFail(_ viewController: TappxRewardedViewController, withError error: TappxErrorAd) {
debugPrint("tappxRewardedViewControllerDidFail with error: \(error)")
}
}