Rewarded Ads
Rewarded ads are full-screened image or video ads that rewards users for viewing the ad.
Implementing View Controller
In the view controller that will present the ad view as subview,
-
add this property
GFPRewardedAdManager *adManager
-
and implement this delegate protocol
GFPRewardedAdManagerDelegate
- Objective-C
- Swift
// MyViewController.h
@import GFPSDK;
@interface MyViewController : UIViewController <GFPRewardedAdManagerDelegate>
@property (nonatomic) GFPRewardedAdManager *adManager;
@end
// MyViewController.h
import GFPSDK
class MyViewController : UIViewController, GFPRewardedAdManagerDelegate {
private var adManager : GFPRewardedAdManager?
}
GFPRewardedAdManager
Initializing GFPRewardedAdManager
Initialize GFPRewardedAdManager
in your view controller, say, in viewDidLoad:
.
-
Provide
GFPRewardedAdManager
with video ad Ad Unit ID (essential) as registered on GFP dashboard, UIView to enclose video view, andGFPAdParam
(optional) for better ad performance. -
Set
GFPRewardedAdManagerDelegate
toGFPRewardedAdManager
Use GFPRewardedAdManager
instance for only single ad request, than create another for the next ad request. It is designed to manage the life cycle of only single ad.
- Objective-C
- Swift
- (void)viewDidLoad {
[super viewDidLoad];
GFPAdParam *adParam = [[GFPAdParam alloc]init];
adParam.yearOfBirth = 1990;
adParam.gender = GFPAdParamGenderTypeMale;
...
self.adManager = [[GFPRewardedAdManager alloc] initWithUnitID:@"UnitID" adParam:adParam];
self.adManager.delegate = self;
self.adManager.requestTimeoutInterval = 60;
}
override func viewDidLoad() {
super.viewDidLoad()
let adParam = GFPAdParam()
adParam.yearOfBirth = 1990
adParam.gender = .male
...
self.adManager = GFPRewardedAdManager(unitID: "UnitID", adParam: adParam)
self.adManager?.delegate = self
self.adManager?.requestTimeoutInterval = 60
}
Loading Ad
Since AppLovin and IronSource runs on a singleton to for loading ads, you can preload only one ad at a time, per Ad Unit ID.
- Objective-C
- Swift
[self.adManager load];
self.adManager?.load()
Showing Ad
On succefully loading ad, GFPRewardedAdManagerDelegates
provides ad through rewardedAdManager:didLoadAd:
.
Than show the rewarded ad at the desired moment, using GFPRewardedAdManager show:
Loaded ads don't have to be shown as soon as being loaded. Thus, preload ads for app's performance.
Be mindful, though, that loaded ads are valid for a only limited time. ex) for DFP, FAN: 60 mins.
- Objective-C
- Swift
[self.adManager show:self];
self.adManager?.show(self)
Resuming Video Ad
For S2S rewarded video ads, if rewarded ad's viewController is presented by super-viewController's present: method, the video is paused by default.
Video must be resumed manually through the GFPRewardedAdMananger by,
- Objective-C
- Swift
[GFPRewardedAdManager resumeCurrentRewardVideo];
GFPRewardedAdManager.resumeCurrentRewardVideo()
Additional Configurations
Ad Request Timeout (per GFPRewardedAdManager)
Set timeout (seconds) for ad requests. GFPInterstitialAdManager
will call rewardedAdManager:didFailWithError:responseInfo:
on timeout. Default is 60 seconds.
- Objective-C
- Swift
self.adManager.requestTimeoutInterval = ...
self.adManager?.requestTimeoutInterval = ...
Ad Request Timeout (global configuration on GFPAdManager)
Set global interstitial timeout (seconds) for ad requests. GFPRewardedAdManager
will call rewardedAdManager:didFailWithError:responseInfo:
on timeout. Default is 60 seconds.
- Objective-C
- Swift
[GFPAdManager adConfiguration].rewardedAdRequestTimeout = ...
GFPAdManager.adConfiguration().rewardedAdRequestTimeout = ...
GFPRewardedAdManagerDelegate
Load Events
On Load Success
- Objective-C
- Swift
- (void)rewardedAdManager:(nonnull GFPRewardedAdManager *)manager didLoadAd:(nonnull GFPRewardedAd *)rewardedAd {
...
}
func rewardedAdManager(_ manager: GFPRewardedAdManager, didLoad rewardedAd: GFPRewardedAd) {
...
}
On Load Failure
rewardedAdMananger:didFailWithError
emits ad load failure, show errors, valid timeout, etc.
- Objective-C
- Swift
- (void)rewardedAdManager:(nonnull GFPRewardedAdManager *)manager didFailWithError:(nonnull GFPError *)error responseInfo:(nullable GFPLoadResponseInfo *)responseInfo {
...
}
func rewardedAdManager(_ manager: GFPRewardedAdManager, didFailWithError error: GFPError, responseInfo:GFPLoadResponseInfo!) {
...
}
LifeCycle Events
On Start Showing Ad
- Objective-C
- Swift
- (void)rewardedAdManager:(nonnull GFPRewardedAdManager *)manager didStartAd:(nonnull GFPRewardedAd *)rewardedAd {
...
}
func rewardedAdManager(_ manager: GFPRewardedAdManager, didStart rewardedAd: GFPRewardedAd) {
...
}
On Rewarding
- Objective-C
- Swift
- (void)rewardedAdManager:(nonnull GFPRewardedAdManager *)manager didCompleteAd:(nonnull GFPRewardedAd *)rewardedAd withReward:(nullable GFPReward *)reward {
...
}
func rewardedAdManager(_ manager: GFPRewardedAdManager, didComplete rewardedAd: GFPRewardedAd, with reward: GFPReward?) {
...
}
FAN and some ad networks does not emit GFPReward, thus, nil is returned instead.
On Dismiss
- Objective-C
- Swift
- (void)rewardedAdManager:(nonnull GFPRewardedAdManager *)manager didCloseAd:(nonnull GFPRewardedAd *)rewardedAd {
...
}
func rewardedAdManager(_ manager: GFPRewardedAdManager, didClose rewardedAd: GFPRewardedAd) {
...
}
On Click
- Objective-C
- Swift
- (void)rewardedAdManager:(nonnull GFPRewardedAdManager *)manager wasClickedAd:(nonnull GFPRewardedAd *)rewardedAd {
...
}
func rewardedAdManager(_ manager: GFPRewardedAdManager, wasClickedAd rewardedAd: GFPRewardedAd) {
...
}
For Google DFP = 7.X.X click events are not supported.