Enabling rewarded ads
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
A rewarded ad is a configurable full-screen ad. The user gets a reward for viewing the ad.
To enable advertising:
Add the import:
import YandexMobileAds
#import <YandexMobileAds/YandexMobileAds.h>
Create
@property
for storing the link to the ad:var rewardedAd: YMARewardedAd!
@property (nonatomic, strong) YMARewardedAd *rewardedAd;
- Initialize the ad:
rewardedAd = YMARewardedAd(adUnitID: “<AdUnitID>”) rewardedAd.delegate = self
self.rewardedAd = [[YMARewardedAd alloc] initWithAdUnitID:<your unique AdUnitID>]; self.rewardedAd.delegate = self;
AdUnitId
is a unique identifier in R-M-XXXXXX-Y format, which is assigned in the Partner Interface.In addition,
self
must conform to the YMARewardedAdDelegate protocol. - Load an ad.
rewardedAd.load()
[self.rewardedAd load];
Optionally, you can use the YMAAdRequest class to transmit the data for targeting. For an example of using the class, see Interstitial ads.
The ad must be pre-loaded in the same orientation as it will be shown (otherwise, the ad will not be shown because the banner size won't match the screen size). Start displaying ads by using this method:
func rewardedAdDidLoad(_ rewardedAd: YMARewardedAd) { rewardedAd.present(from: self) }
- (void)rewardedAdDidLoad:(YMARewardedAd *)rewardedAd { [rewardedAd presentFromViewController:self]; }
If you are using the “client-side reward” mechanism, implement the - rewardedAd:didReward: delegate method. It is called when the impression is registered and the user can be rewarded for viewing the ad. Use this chance to give the reward to the app user.
You can optionally enable logging by using the +enableLogging method. If an impression wasn't registered, a message appears in the console.
To find out why ads aren't working correctly, use the methods
func rewardedAdDidFail(toLoad rewardedAd: YMARewardedAd, error: Error) func rewardedAdDidFail(toPresent rewardedAd: YMARewardedAd, error: Error)
- (void)rewardedAdDidFailToLoad:(YMARewardedAd *)rewardedAd error:(NSError *)error; - (void)rewardedAdDidFailToPresent:(YMARewardedAd *)rewardedAd error:(NSError *)error;
For error descriptions, see YMAAdErrorCode.
AdUnitId
:demo-rewarded-yandex