Rewarded
This guide explains how to integrate Rewarded using the Ogury SDK in your iOS application.
Prerequisites
Before proceeding, make sure you have completed the steps outlined in the Getting Started section:
Registered your app and created ad units in the Ogury Publisher Platform.
Retrieved your asset key and ad unit IDs.
Updated your
app-ads.txt
file.
Before integrating any ad format, ensure you have completed the SDK Setup:
Integrated and initialized the Ogury SDK in your app.
Load a Rewarded ad
To load a Rewarded ad:
Instantiate a
OguryRewardedAd
object with a valid Rewarded ad unit ID.Call its
load()
method.
import UIKit
import OguryAds
class ViewController: UIViewController {
private(set) var rewardedAd: OguryRewardedAd!
override func viewDidLoad() {
super.viewDidLoad()
rewardedAd = OguryRewardedAd(adUnitID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
rewardedAd.load()
}
}
The OguryRewardedAd
initializer takes the following parameters:
Your Ogury ad unit ID for the Rewarded ad. It is in the form of a UUID, which consists of a 36-character string formatted as follows:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
, where eachx
represents a hexadecimal digit. See Ad Unit Creation if you haven’t generated one.If you are building a mediation adapter, an additional parameter,
OguryMediation
which should be instantiated with:name
: the name of the mediation.version
: the version of the mediation SDK.
self.rewardedAd = OguryRewardedAd(
adUnitId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
mediation: OguryMediation(name: "your mediation name",
version: "your mediation SDK version")
)
Register for callbacks
You can monitor the lifecycle of your Rewarded ad by implementing the OguryRewardedAdDelegate
protocol. This delegate provides real-time updates on key events, such as successful ad loading, display, reward or errors.
To use it, set your class as the delegate of OguryRewardedAd
and implement the necessary methods. This ensures timely notifications, allowing you to manage the ad experience effectively.
If the rewardedAd:didFailWithError:
callback is triggered, refer to the Ad Error handling section below for detailed information on troubleshooting.
The rewardedAd:didReceive:
callback specifically allows you to handle the rewards given to users after they interact with the ad. The reward name
and value
can be set in the Reward Settings section of your ad unit on the Ogury Dashboard.
override func viewDidLoad() {
super.viewDidLoad()
rewardedAd = OguryRewardedAd(
adUnitID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
)
rewardedAd.delegate = self
rewardedAd.load()
}
// Called when the ad is loaded and ready to be shown
func rewardedAdDidLoad(_ rewardedAd: OguryRewardedAd) {
// Call show() to display the ad
}
// Called when an impression is recorded
func rewardedAdDidTriggerImpression(_ rewardedAd: OguryRewardedAd) {
// Track ad performance here
}
// Called when the user clicks on the ad
func rewardedAdDidClick(_ rewardedAd: OguryRewardedAd) {
// Handle ad click tracking here
}
// Called when the ad is closed
func rewardedAdDidClose(_ rewardedAd: OguryRewardedAd) {
// Resume app flow after ad is closed
}
// Called when the reward is granted
func rewardedAd(_ rewardedAd: OguryRewardedAd, didReceive reward: OguryReward) {
}
// Called when the ad fails to load or display
func rewardedAd(_ rewardedAd: OguryRewardedAd,
didFailWithError error: OguryAdError) {
switch error.type {
case .load:
// Handle loading error
case .show:
// Handle display error
}
}
Show a Rewarded ad
To display a loaded Rewarded ad, invoke the show()
method on the instantiated OguryRewardedAd
object.
if rewardedAd.isLoaded {
// The ad is loaded and ready to be displayed.
rewardedAd.show(in: self)
} else {
// The ad is not loaded yet. Handle this situation appropriately.
}
The show()
method takes the following parameter:
A reference to the
ViewController
where the Rewarded ad will be presented.
Always check isLoaded
before calling show()
, unless you are calling directly from the rewardedAdDidLoad
callback.
Additional Resources
Integration Testing
Ensure your implementation works correctly by testing with test ads and verifying ad behavior.
See the Testing Guide.
Ad Error Handling
If Rewarded ads fail to load or display, we recommend implementing and logging the callbacks from OguryRewardedAdDelegate
to track the full ad lifecycle. Pay particular attention to the rewardedAd:didFailWithError
callback, which returns an OguryAdError
object containing detailed information about the failure.
For a full list of error types, refer to the Ad Error Handling page.
Migration Guide
Still using Ogury SDK v4? Follow our step-by-step migration guide to smoothly upgrade to v5 and take advantage of the latest features and improvements.
View the Migration Guide.
Last updated
Was this helpful?