iOS SDK: Rewarded video

The myTarget SDK provides the ability to display an rewarded ads in your app

Initialization

To display rewarded ad in your app, create an instance of the MTRGRewardedAd class. You must specify your slotId when creating an instance.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGRewardedAd *_ad;
}
 
- (void)initAd
{
    // Enabling debug mode
    // [MTRGRewardedAd setDebugMode:YES];
     
    // Create an instance of MTRGRewardedAd
    _ad = [MTRGRewardedAd rewardedAdWithSlotId:YOUR_SLOT_ID];
}

Loading ads

To receive notifications (such as ad load succeeded, ad load failed, reward earned, ad clicked etc.), you must set a delegate, which implements the MTRGRewardedAdDelegate protocol, on the MTRGRewardedAd instance. Then you can start loading ad.
@interface YourViewController : UIViewController <MTRGRewardedAdDelegate>
@end
 
@implementation YourViewController
{
  MTRGRewardedAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGRewardedAd
    _ad = [MTRGRewardedAd rewardedAdWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _ad.delegate = self;
     
    // Start loading ad
    [_ad load];
}
  
- (void)onLoadWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
}
 
- (void)onNoAdWithReason:(NSString *)reason rewardedAd:(MTRGRewardedAd *)rewardedAd
{
}
 
- (void)onReward:(MTRGReward *)reward rewardedAd:(MTRGRewardedAd *)rewardedAd
{
}
 
- (void)onClickWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
}
 
- (void)onCloseWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
}
 
- (void)onDisplayWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
}
 
- (void)onLeaveApplicationWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
}

Displaying ads

After the ad has loaded successfully, you can start displaying rewarded ad.
- (void)onLoadWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
    [_ad showWithController:self];
}

MTRGReward

When reward is received, notification onReward:rewardedAd: will be called on delegate with MTRGReward object containing field type
@property(nonatomic, readonly) NSString *type;
Was this article helpful?
Yes
No