Rewarded Ads
First of all, you need to create a RewardedAdController object and init it (with your application context in parameter). After this, you have two possibilities:
  • Display as quickly as possible the ad after loading it. For this, you can simply call the method Adstronomic.loadAndShow with the app context and the ad object as parameters.
  • Just load the ad in the background by calling Adstronomic.loadRewarded(). And, when you want to show the ad (after a specific event - For example: click on a button) you can do it with self.present of your view.
So, for example:
Swift
var rewardedAd: RewardedAdController?
​
rewardedAd = RewardedAdController.initializeObject()
Adstronomic.loadAndShow(view: self, ad: rewardedAd!)
or
Swift
var rewardedAd: RewardedAdController?
​
Adstronomic.loadRewarded()
rewardedAd = RewardedAdController.initializeObject()
​
...
​
// Call when a button is pressed for example
if rewardedAd != nil {
self.present(rewardedAd!, animated: true, completion: nil)
}

Listener

If you want to unlock reward or detect when an error occurred (ads not available because of internet connection issue). You can add a listener in order to execute your custom logic. For this, see the following example:
Swift
rewardedAd?.setOnAdLoadFailed {
// Your code here
}
​
rewardedAd?.setOnAdLoaded {
// Your code here
}
​
rewardedAd?.setOnAdClosed {
print("Rewarded Ad Closed!")
}
​
rewardedAd?.setOnAdShown {
// Your code here
}
Each event is self explanatory. For example, if you want to give a reward to the player, execute this code in setOnAdClosed.
Copy link