Ad Formats iOS

Banners

Initialization

To display adaptive, 320x50, 300x250 and 728x90 banners in your app, you must create an instance of the MTRGAdView class. MTRGAdView is a visual component (subclass of UIView) that must be added to the app's screen.
The MTRGAdView's minimum size must be 320x50 pixels for 320x50 format, 300x250 pixels for 300x250 format and 728x90 pixels for 728x90 format. To create an instance of MTRGAdView, specify your slotId. You shouldn't set frame.size for MTRGAdView.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGAdView *_adView;
}
 
- (void)initAd
{
    // Enabling debug mode
    // [MTRGAdView setDebugMode:YES]; 
     
    // Create an instance of MTRGAdView, adaptive format
    _adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID];
  
    // 300x250 format
    // _adView.adSize = MTRGAdSizeType300x250;
}
By default MTRGAdSizeTypeAdaptive format will be used. In this case banner will be automatically resized by screen's width with respect to aspect ratio, height will become not less than 50 pixels, but not grater than 15% of screen's height.

There is an ability to redefine adSize property. Then SDK will discontinue observing device's orientation changes and stop adjusting banner's size. So in this case if you use adaptive size you should observe orientation changes:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    _adView.adSize = [MTRGAdSize adSizeForCurrentOrientation];
}
If load() method already called, you can't change format to 300x250 anymore (also can't set other format if 300x250 used before).

MTRGAdSize

MTRGAdSize - an object which allows you to define a size of MTRGAdView. Following sizes are available: MTRGAdSizeType320x50, MTRGAdSizeType300x250, MTRGAdSizeType728x90, MTRGAdSizeTypeAdaptive.
+ (instancetype)adSize320x50;
+ (instancetype)adSize300x250;
+ (instancetype)adSize728x90;
+ (instancetype)adSizeForCurrentOrientation; // Adaptive
+ (instancetype)adSizeForCurrentOrientationForWidth:(CGFloat)width; // Adaptive with maximum width restriction

Loading and displaying ads

The newly created and initialized MTRGAdView instance must be added to the app's screen. To handle clicks, you must set current ViewController on the MTRGAdView instance. To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must set a delegate, which implements the MTRGAdViewDelegate protocol, on the MTRGAdView instance, and then start loading ad. After ad has loaded successfully, you can start displaying ad.
@interface YourViewController : UIViewController <MTRGAdViewDelegate>
@end
 
@implementation YourViewController
{
  MTRGAdView *_adView;
}
 
- (void)initAd
{
    // Create an instance of MTRGAdView
    _adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _adView.delegate = self;
  
    // Set the controller
    _adView.viewController = self;
 
    // Add to display
    [self.view addSubview: _adView];
     
    // Start loading ad
    [_adView load];
}
  
- (void)onLoadWithAdView:(MTRGAdView *)adView
{
}
 
- (void)onNoAdWithReason:(NSString *)reason adView:(MTRGAdView *)adView
{
}
 
- (void)onAdShowWithAdView:(MTRGAdView *)adView
{
}
 
- (void)onAdClickWithAdView:(MTRGAdView *)adView
{
}
 
- (void)onShowModalWithAdView:(MTRGAdView *)adView
{
}
  
- (void)onDismissModalWithAdView:(MTRGAdView *)adView
{
}
  
- (void)onLeaveApplicationWithAdView:(MTRGAdView *)adView
{
}

Rotation

Ads are rotated every 60 seconds. You can disable automatic ad rotation by specifying the optional shouldRefreshAd parameter when initializing the MTRGAdView instance. Rotation is available for all banners except of 300x250 format.
// Disable automatic ad rotation
_adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID shouldRefreshAd:NO];
Banner 320x50

Interstitial Ads

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

Initialization

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

Loading ads

To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must set a delegate, which implements the MTRGInterstitialAdDelegate protocol, on the MTRGInterstitialAd instance. Then you can start loading ad.
@interface YourViewController : UIViewController <MTRGInterstitialAdDelegate>
@end
 
@implementation YourViewController
{
  MTRGInterstitialAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGInterstitialAd
    _ad = [MTRGInterstitialAd interstitialAdWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _ad.delegate = self;
     
    // Start loading ad
    [_ad load];
}
  
- (void)onLoadWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
}
  
- (void)onNoAdWithReason:(NSString *)reason interstitialAd:(MTRGInterstitialAd *)interstitialAd
{
}
  
- (void)onDisplayWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
}
 
- (void)onClickWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
}
 
- (void)onCloseWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
}
  
- (void)onLeaveApplicationWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
}

Displaying ads

After the ad has loaded successfully, you can start displaying interstitial ad.
- (void)onLoadWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
    [_ad showWithController:self];
}
Example Interstitial Banner

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;

Native Ads

The myTarget SDK provides the ability to display ads in your app using native visual components. The SDK loads the ad and gives the app an ad model with specific properties and methods for counting impressions and handing clicks. The API also provides a build-in visual component that you can use in your app, instead of creating your own.

Initialization

To display native ads in your app, you must create an instance of the MTRGNativeAd class and specify your slotId.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGNativeAd *_ad;
}
 
- (void)initAd
{
    // Enabling debug mode
    // [MTRGNativeAd setDebugMode:YES];
     
    // Create an instance of MTRGNativeAd
    _ad = [MTRGNativeAd nativeAdWithSlotId:YOUR_SLOT_ID];
}

Loading ads

To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must set a delegate, which implements the MTRGNativeAdDelegate protocol, on the MTRGNativeAd instance. Then you can load the ad.
@interface YourViewController : UIViewController <MTRGNativeAdDelegate>
@end
 
@implementation YourViewController
{
  MTRGNativeAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGNativeAd
    _ad = [MTRGNativeAd nativeAdWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _ad.delegate = self;
     
    // Start loading ad
    [_ad load];
}
  
- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
}
  
- (void)onNoAdWithReason:(NSString *)reason nativeAd:(MTRGNativeAd *)nativeAd
{
}
  
- (void)onAdClickWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
  
- (void)onShowModalWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
  
- (void)onDismissModalWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
  
- (void)onLeaveApplicationWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onVideoPlayWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onVideoPauseWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onVideoCompleteWithNativeAd:(MTRGNativeAd *)nativeAd
{
}

Autoloading images and video

By default, all media-objects (images, video) is loaded. You can disable automatic images and/or video loading using cachePolicy property, but keep in mind that loading images and video requires additional time, which makes it take longer for ads to be displayed in your app.
_ad.cachePolicy = MTRGCachePolicyNone;
[_ad load];
Allowed values: MTRGCachePolicyAll (by default), MTRGCachePolicyImages, MTRGCachePolicyVideo, MTRGCachePolicyNone.

If preloading is on, then corresponding media-files (images and/or video) will be downloaded and stored into cache at the same time with main ad data loading.

If preloading of images is off, then it will be asynchronously and automatically loaded at the time of method registerView() call. No additional actions are required.

If preloading of video is off, then it will be loaded (streamed) during playback.

Displaying ads

After successfully loading the ad, you can use the properties of the banner object to initialize your visual component. Which properties are available depends on what is being advertised, i.e. they differ for apps and websites.

To display icon image you should use MTRGIconAdView class. To display main image, carousel and video playback, you must use an instance of MTRGMediaAdView class from myTarget SDK.

myTargetSDK automatically detects if MTRGMediaAdView is contained within visual component and adds a horizontal cards slider (if cards exists in banner) or video (if there is no cards but video exists).

After initializing a visual component, use the registerView method to register it with the MTRGNativeAd instance. If you are going to use the same visual component to display other ads, you must first call the unregisterView method on the current MTRGNativeAd instance before calling registerView on another MTRGNativeAd instance. Impressions and clicks are processed automatically, and the application should not block or capture user touch events on this visual component. The properties available are described below, and examples of initializing visual components for different types of banners are given.

Visual components (built-in and custom) should be embedded into MTRGNativeAdContainer object.
You can pass either component itself or container when call method registerView.
When container created, visual component adView will be added as subview of container and will fit it's bounds.
In order to calculate height of visual component depending on it's width (required for TableView/CollectionView), you can call method sizeThatFits of container object.
When container created, you should setup bindings between properties of visual component (adView) and container's properties.

- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
    // Ad title
    NSString *title = promoBanner.title;
    // Main text
    NSString *descriptionText = promoBanner.descriptionText;
    // Age limit. May be nil
    NSString *ageRestrictions = promoBanner.ageRestrictions;
    // Disclaimer. May be nil
    NSString *disclaimer = promoBanner.disclaimer;
    // "Advertising" label text
    NSString *advertisingLabel = promoBanner.advertisingLabel;
    // Icon
    MTRGImageData *icon = promoBanner.icon;
    // Call-to-action text for the button
    NSString *ctaText = promoBanner.ctaText;
    // Properties available only for ads promoting apps
    if (promoBanner.navigationType == MTRGNavigationTypeStore))
    {
        // App rating (0-5)
        NSNumber *rating = promoBanner.rating;
        // Number of votes
        NSUInteger votes = promoBanner.votes;
        // App category
        NSString *category = promoBanner.category;
        // App subcategory
        NSString *subcategory = promoBanner.subcategory;
    }
    // Properties available only for ads promoting websites
    else if (promoBanner.navigationType == MTRGNavigationTypeWeb)
    {
        // Website domain
        NSString *domain = promoBanner.domain;
    }
     
    // Use properties to build your visual component
    UIView *adView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 10, 200, 20)];
    titleLabel.text = title;
    UILabel *descLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 50, 200, 40)];
    descLabel.text = descriptionText;
    UIButton *ctaButton = [[UIButton alloc] initWithFrame:CGRectMake(210, 260, 80, 30)];
    [ctaButton setTitle:ctaText forState:UIControlStateNormal];
     
    // Create an instance of MTRGMediaAdView
    MTRGMediaAdView *mediaView = [MTRGNativeViewsFactory createMediaAdView];
    mediaView.frame = CGRectMake(10, 100, 280, 150);
    MTRGIconAdView *iconAdView = [MTRGNativeViewsFactory createIconAdView];
    iconAdView.frame = CGRectMake(10, 10, 50, 50);
     
    [adView addSubview:titleLabel];
    [adView addSubview:descLabel];
    [adView addSubview:iconAdView];
    [adView addSubview:mediaView];
    [adView addSubview:ctaButton];
 
    MTRGNativeAdContainer *containerView = [MTRGNativeAdContainer createWithAdView:adView];
    containerView.titleView = titleLabel;
    containerView.descriptionView = descLabel;
    containerView.iconView = iconAdView;
    containerView.mediaView = mediaView;
    containerView.ctaView = ctaButton;
 
    // Register the view
    [nativeAd registerView:containerView withController:self];
  
    // Add it to the screen
    [self.view addSubview:containerView];
}
App:
Пример полноэкранного баннера
Website:
Пример полноэкранного баннера

Setting size of MediaAdView

Aspect ratio of loaded image can be different to size of mediaView and you should adjust size using actual mediaAdView.aspectRatio value.

Notification about size change can be received using delegate onImageSizeChanged of object mediaAdView

mediaAdView.delegate = self;
  
- (void)onImageSizeChanged:(MTRGMediaAdView *)mediaAdView
{
    CGFloat currentAspect = mediaView.frame.size.width / mediaView.frame.size.height;
    NSLog(@"current aspect of media view: %f", currentAspect);
    
    CGFloat actualAspect = mediaView.aspectRatio;
    NSLog(@"actual aspect of media view: %f", actualAspect);
}

AdChoices icon

myTarget SDK automatically adds the AdChoices icon to each visual component. The AdChoices icon is added to the top right corner by default. You can select the preferred corner using the adChoicesPlacement property:
...
_ad.adChoicesPlacement = MTRGAdChoicesPlacementTopRight;
[_ad load]; 

Setting clickable area

In the example above, the visual component is registered using the registerView:withController method. In this case, the entire area of the visual component is clickable. MyTarget SDK provides the ability to register list of visual components that can be clicked. To do this, use the registerView:withController:withClickableViews method:
- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
    ...
    ...
    ...
      
    // Register the view with clickable titleView and button
    [nativeAd registerView:adView withController:self withClickableViews:@[titleLabel, ctaButton]];
   
    // Add it to the screen
    [self.view addSubview:adView];
}

Using built-in visual component

The myTarget SDK provides built-in visual component whose appearance you can customize to fit the design of your app.

We give an example below and describe the settings available.

MTRGNativeAdView
- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
    // Create an instance of MTRGNativeAdView
    MTRGNativeAdView *adView = [MTRGNativeViewsFactory createNativeAdView];
    adView.banner = promoBanner;
  
    // Available for customization internal views
    UILabel *titleLabel = adView.titleLabel;
    UILabel *descriptionLabel = adView.descriptionLabel;
    MTRGIconAdView *iconAdView = adView.iconAdView;
    MTRGMediaAdView *mediaView = adView.mediaAdView;
    UILabel *domainLabel = adView.domainLabel;
    UILabel *categoryLabel = adView.categoryLabel;
    UILabel *disclaimerLabel = adView.disclaimerLabel;
    MTRGStarsRatingView *ratingStarsView = adView.ratingStarsView;
    UILabel *votesLabel = adView.votesLabel;
    UIView *buttonView = adView.buttonView;
    UILabel *buttonToLabel = adView.buttonToLabel;
    UILabel *ageRestrictionsLabel = adView.ageRestrictionsLabel;
    UILabel *adLabel = adView.adLabel;
  
    // Margins
    UIEdgeInsets titleMargins = adView.titleMargins;
    UIEdgeInsets domainMargins = adView.domainMargins;
    UIEdgeInsets categoryMargins = adView.categoryMargins;
    UIEdgeInsets descriptionMargins = adView.descriptionMargins;
    UIEdgeInsets disclaimerMargins = adView.disclaimerMargins;
    UIEdgeInsets imageMargins = adView.imageMargins;
    UIEdgeInsets iconMargins = adView.iconMargins;
    UIEdgeInsets ratingStarsMargins = adView.ratingStarsMargins;
    UIEdgeInsets votesMargins = adView.votesMargins;
    UIEdgeInsets buttonMargins = adView.buttonMargins;
    UIEdgeInsets buttonCaptionMargins = adView.buttonCaptionMargins;
    UIEdgeInsets adLabelMargins = adView.adLabelMargins;
    UIEdgeInsets ageRestrictionsMargins = adView.ageRestrictionsMargins;
        
    // Register the view
    [nativeAd registerView:adView withController:self];
     
    // Add it to the screen
    [self.view addSubview:adView];
}
App:
Website:
Video:
Cards:

Loading multiple banners

The myTarget SDK provides classes MTRGNativeAdLoader, which allows you to load from 1 to 20 banners per one request. For MTRGNativeAdLoader, you can configure all the same settings that are available for customization in MTRGNativeAd (for example, user's gender and age, autoloading images and videos). There is no guarantee that the number of banners specified in the COUNT parameter will be loaded - this parameter indicates the maximum number of banners that you want to receive.
// Enabling debug mode
// [MTRGNativeAdLoader setDebugMode:YES];
 
 
// Create an instance of MTRGNativeAdLoader
MTRGNativeAdLoader *nativeAdLoader = [MTRGNativeAdLoader loaderForCount:COUNT slotId:YOUR_SLOT_ID];
 
// Loading ads
[nativeAdLoader loadWithCompletionBlock:^(NSArray<MTRGNativeAd *> * _Nonnull nativeAds)
{
    for (MTRGNativeAd *nativeAd in nativeAds)
    {
        // Set the delegate
        nativeAd.delegate = self;
         
        MTRGNativePromoBanner *promoBanner = nativeAd.banner;
        // The same code as in onLoadWithNativePromoBanner method of MTRGNativeAdDelegate protocol
    }
}];
The resulting array will contain from 0 to COUNT instances of MTRGNativeAd - each of them contains already loaded MTRGNativePromoBanner and with each of them it is necessary to work the same as described in this documentation above, starting from the onLoadWithNativePromoBanner method.

Native Banners

The myTarget SDK provides the ability to display ads in your app using native visual components. The SDK loads the ad and gives the app an ad model with specific properties and methods for counting impressions and handing clicks. The API also provides a build-in visual component that you can use in your app, instead of creating your own.

Native Banner doesn't support MTRGMediaAdView, so it can't display media content (video, cards, big image).

Initialization

To display native banners in your app, you must create an instance of the MTRGNativeBannerAd class and specify your slotId.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGNativeBannerAd *_ad;
}
 
- (void)initAd
{
    // Enabling debug mode
    // [MTRGNativeBannerAd setDebugMode:YES];
     
    // Create an instance of MTRGNativeAd
    _ad = [MTRGNativeBannerAd nativeBannerAdWithSlotId:YOUR_SLOT_ID];
}

Loading ads

To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must set a delegate, which implements the MTRGNativeBannerAdDelegate protocol, on the MTRGNativeBannerAd instance. Then you can load the ad.
@interface YourViewController : UIViewController <MTRGNativeBannerAdDelegate>
@end
 
@implementation YourViewController
{
  MTRGNativeBannerAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGNativeBannerAd
    _ad = [MTRGNativeBannerAd nativeBannerAdWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _ad.delegate = self;
     
    // Start loading ad
    [_ad load];
}
  
- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}
  
- (void)onNoAdWithReason:(NSString *)reason nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}
  
- (void)onAdShowWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}
  
- (void)onAdClickWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}
  
- (void)onShowModalWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}
  
- (void)onDismissModalWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}
  
- (void)onLeaveApplicationWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
}

Autoloading images

By default, all images is loaded. You can disable automatic images loading using cachePolicy property, but keep in mind that loading images requires additional time, which makes it take longer for ads to be displayed in your app.
_ad.cachePolicy = MTRGCachePolicyNone;
[_ad load];
Allowed values: MTRGCachePolicyAll (by default), MTRGCachePolicyImages, MTRGCachePolicyNone.

If preloading is on, then corresponding images will be downloaded and stored into cache at the same time with main ad data loading.

If preloading of images is off, then it will be asynchronously and automatically loaded at the time of method registerView() call. No additional actions are required.

Displaying ads

After successfully loading the ad, you can use the properties of the banner object to initialize your visual component. Which properties are available depends on what is being advertised, i.e. they differ for apps and websites.

To display icon image you should use MTRGIconAdView class from myTarget SDK.

After initializing a visual component, use the registerView method to register it with the MTRGNativeBannerAd instance. If you are going to use the same visual component to display other ads, you must first call the unregisterView method on the current MTRGNativeBannerAd instance before calling registerView on another MTRGNativeBannerAd instance. Impressions and clicks are processed automatically, and the application should not block or capture user touch events on this visual component. The properties available are described below, and examples of initializing visual components for different types of banners are given.

Visual components (built-in and custom) should be embedded into MTRGNativeAdContainer object.
You can pass either component itself or container when call method registerView.
When container created, visual component adView will be added as subview of container and will fit it's bounds.
In order to calculate height of visual component depending on it's width (required for TableView/CollectionView), you can call method sizeThatFits of container object.
When container created, you should setup bindings between properties of visual component (adView) and container's properties.

- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
    // Ad title
    NSString *title = banner.title;
    // Age restrictions. Can be nil
    NSString *ageRestrictions = banner.ageRestrictions;
    // Disclaimer. Can be nil
    NSString *disclaimer = banner.disclaimer;
    // "Advertising" label text
    NSString *advertisingLabel = banner.advertisingLabel;
    // Icon
    MTRGImageData *icon = banner.icon;
    // Call-to-action text for the button
    NSString *ctaText = banner.ctaText;
    // Properties available only for ads promoting apps
    if (banner.navigationType == MTRGNavigationTypeStore))
    {
        // App rating (0-5)
        NSNumber *rating = banner.rating;
        // Number of votes
        NSUInteger votes = banner.votes;
    }
    // Properties available only for ads promoting websites
    else if (banner.navigationType == MTRGNavigationTypeWeb)
    {
        // Website domain
        NSString *domain = banner.domain;
    }
     
    // Use properties to build your visual component
    UIView *adView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
  
    MTRGIconAdView *iconAdView = [MTRGNativeViewsFactory createIconAdView];
    iconAdView.frame = CGRectMake(0, 0, 50, 50);
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 15, 140, 20)];
    titleLabel.text = title;
    UIButton *ctaButton = [[UIButton alloc] initWithFrame:CGRectMake(210, 10, 80, 30)];
    [ctaButton setTitle:ctaText forState:UIControlStateNormal];
     
    [adView addSubview:titleLabel];
    [adView addSubview:descLabel];
    [adView addSubview:iconAdView];
    [adView addSubview:mediaView];
    [adView addSubview:ctaButton];
 
    MTRGNativeAdContainer *containerView = [MTRGNativeAdContainer createWithAdView:adView];
    containerView.titleView = titleLabel;
    containerView.iconView = iconAdView;
    containerView.ctaView = ctaButton;
 
    // Register the view
    [nativeBannerAd registerView:containerView withController:self];
  
    // Add it to the screen
    [self.view addSubview:containerView];
}
App:
Web resource:

AdChoices icon

myTarget SDK automatically adds the AdChoices icon to each visual component. The AdChoices icon is added to the top right corner by default. You can select the preferred corner using the adChoicesPlacement property:
...
_ad.adChoicesPlacement = MTRGAdChoicesPlacementTopRight;
[_ad load]; 

Setting clickable area

In the example above, the visual component is registered using the registerView:withController method. In this case, the entire area of the visual component is clickable. MyTarget SDK provides the ability to register list of visual components that can be clicked. To do this, use the registerView:withController:withClickableViews method:
- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
    ...
    ...
    ...
      
    // Register the view with clickable titleView and button
    [nativeBannerAd registerView:adView withController:self withClickableViews:@[titleLabel, ctaButton]];
   
    // Add it to the screen
    [self.view addSubview:adView];
}

Using a built-in visual component

The myTarget SDK provides built-in visual component whose appearance you can customize to fit the design of your app.

We give an example below and describe the settings available.

MTRGNativeBannerAdView
- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
    // Create an instance of MTRGNativeBannerAdView
    MTRGNativeBannerAdView *adView = [MTRGNativeViewsFactory createNativeBannerAdView];
    adView.banner = banner;
  
    // Available for customization internal views
    UILabel *titleLabel = adView.titleLabel;
    MTRGIconAdView *iconAdView = adView.iconAdView;
    UILabel *domainLabel = adView.domainLabel;
    UILabel *disclaimerLabel = adView.disclaimerLabel;
    MTRGStarsRatingView *ratingStarsView = adView.ratingStarsView;
    UILabel *votesLabel = adView.votesLabel;
    UIView *buttonView = adView.buttonView;
    UILabel *buttonToLabel = adView.buttonToLabel;
    UILabel *ageRestrictionsLabel = adView.ageRestrictionsLabel;
    UILabel *adLabel = adView.adLabel;
  
    // Margins
    UIEdgeInsets titleMargins = adView.titleMargins;
    UIEdgeInsets domainMargins = adView.domainMargins;
    UIEdgeInsets disclaimerMargins = adView.disclaimerMargins;
    UIEdgeInsets iconMargins = adView.iconMargins;
    UIEdgeInsets ratingStarsMargins = adView.ratingStarsMargins;
    UIEdgeInsets votesMargins = adView.votesMargins;
    UIEdgeInsets buttonMargins = adView.buttonMargins;
    UIEdgeInsets buttonCaptionMargins = adView.buttonCaptionMargins;
    UIEdgeInsets adLabelMargins = adView.adLabelMargins;
    UIEdgeInsets ageRestrictionsMargins = adView.ageRestrictionsMargins;
        
    // Register the view
    [nativeBannerAd registerView:adView withController:self];
     
    // Add it to the screen
    [self.view addSubview:adView];
}
Application:
Web resource:

Loading of multiple banners

The myTarget SDK provides class MTRGNativeBannerAdLoader, which allows you to load from 1 to 20 banners per one request. For MTRGNativeBannerAdLoader, you can configure all the same settings that are available for customization in MTRGNativeBannerAd (for example, user's gender and age, autoloading images and videos). There is no guarantee that the number of banners specified in the COUNT parameter will be loaded - this parameter indicates the maximum number of banners that you want to receive.
// Enabling debug mode
// [MTRGNativeBannerAdLoader setDebugMode:YES];
 
 
// Create an instance of MTRGNativeBannerAdLoader
MTRGNativeBannerAdLoader *nativeBannerAdLoader = [MTRGNativeBannerAdLoader loaderForCount:COUNT slotId:YOUR_SLOT_ID];
 
// Loading ads
[nativeBannerAdLoader loadWithCompletionBlock:^(NSArray<MTRGNativeBannerAd *> * _Nonnull nativeBannerAds)
{
    for (MTRGNativeBannerAd *nativeBannerAd in nativeBannerAds)
    {
        // Set the delegate
        nativeBannerAd.delegate = self;
         
        MTRGNativeBanner *banner = nativeBannerAd.banner;
        // The same code as in onLoadWithNativeBanner method of MTRGNativeBannerAdDelegate protocol
    }
}];
The resulting array will contain from 0 to COUNT instances of MTRGNativeBannerAd - each of them contains already loaded MTRGNativeBanner and with each of them it is necessary to work the same as described in this documentation above, starting from the onLoadWithNativeBanner method.

In-stream video

myTarget SDK provides the ability to show in-stream video ads in your app while watching videos. Ads can be shown before a video (preroll), during a show (midroll), and after a show (postroll).

The SDK downloads the data and gives the app the ability to display ads both in its video player and in the app's player.

Initialization

To display an ad video in your app, you must create an instance of the MTRGInstreamAd class. To create an instance of MTRGInstreamAd, you must specify your slotId. For each video in the application, you need to create your own instance of the MTRGInstreamAd class.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGInstreamAd *_ad;
}
 
- (void)initAd
{
    // Enable debug mode
    // [MTRGInstreamAd setDebugMode:YES];
    // Create an instance of MTRGInstreamAd
    _ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
}

Using the application player

To play ads in the application player, it must implement the MTRGInstreamAdPlayer Protocol and notify the MTRGInstreamAdPlayerDelegate delegate installed by it.

To use your player you need to install it to the created player instance MTRGInstreamAd.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGInstreamAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGInstreamAd
    _ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
     
    // Install the player
    _ad.player = YOUR_PLAYER;
}

Protocol MTRGInstreamAdPlayer

The MTRGInstreamAdPlayer Protocol methods are called by the MTRGInstreamAd instance. You do not need to call them yourself.
@property(nonatomic, readonly) NSTimeInterval adVideoDuration;
The duration of the promotional video.
@property(nonatomic, readonly) NSTimeInterval adVideoTimeElapsed;
The current position of the promotional video. The method is called multiple times during ad video playback and should return the actual value in seconds.
@property(nonatomic, weak) id <MTRGInstreamAdPlayerDelegate> adPlayerDelegate;
Sets the delegate of the player.
@property(nonatomic, readonly) UIView *adPlayerView;
Visual representation of the player, usually self.
@property(nonatomic) float volume;
Sets the volume from 0 to 1.
- (void)playAdVideoWithUrl:(NSURL *)url;
Starts playback of the promotional video.

url - path to the video
- (void)pauseAdVideo;
Pauses the playback of the advertising video.
- (void)resumeAdVideo;
Resumes playing the promotional video.
- (void)stopAdVideo;
Stops the playback of the advertising video.

Protocol MTRGInstreamAdPlayerDelegate

The MTRGInstreamAdPlayerDelegate Protocol callback methods for the installed delegate must be called by the player in response to calls to the MTRGInstreamAdPlayer Protocol methods when certain events occur.
- (void)onAdVideoStart;
Method should be invoked after a successful start of playback of the advertising video as a response to the call playAdVideo.
- (void)onAdVideoPause;
The method should be called after pausing ad video playback as a response to the pauseAdVideo method call.
- (void)onAdVideoResume;
Method should be invoked after the resumption of the playback of the advertising video as a response to the call resumeAdVideo.
- (void)onAdVideoStop;
The method should be called after the ad video playback stops, as a response to the stopAdVideo method call.
- (void)onAdVideoErrorWithReason:(NSString *)reason;
Method should be invoked upon the occurrence of any error during the playback of the advertising video.
- (void)onAdVideoComplete;
The method must be called when the ad video is finished playing.

Using the SDK player

myTarget SDK provides a ready-made player for playing ads. To use the SDK player, simply call the useDefaultPlayer method on the created MTRGInstreamAd instance and add the player to the application screen.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGInstreamAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGInstreamAd
    _ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
     
    // Install the player SDK
    [_ad useDefaultPlayer];
    // Add player to the screen
    [self.view addSubview:_ad.player.adPlayerView];
}

Download ads

To receive notifications (such as a successful data download or a download error, an ad impression), you must install a delegate that implements the MTRGInstreamAdDelegate Protocol on the created instance of MTRGInstreamAd, and then you can start the data download.
@interface YourViewController : UIViewController <MTRGInstreamAdDelegate>
@end
 
@implementation YourViewController
{
  MTRGInstreamAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGInstreamAd
    _ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _ad.delegate = self;
 
    // Start loading data
    [_ad load];
}
 
- (void)onLoadWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
   // The data was successfully loaded
}
 
- (void)onNoAdWithReason:(NSString *)reason instreamAd:(MTRGInstreamAd *)instreamAd
{
   // No data received
}
 
- (void)onErrorWithReason:(NSString *)reason instreamAd:(MTRGInstreamAd *)instreamAd
{
   // An error occurred while playing the promotional video
}
 
- (void)onBannerStart:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
   // Began playing the promotional video
}
 
- (void)onBannerComplete:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
   // Ad video playback completed
}
 
- (void)onBannerTimeLeftChange:(NSTimeInterval)timeLeft duration:(NSTimeInterval)duration instreamAd:(MTRGInstreamAd *)instreamAd
{
   // Is called multiple times during playback of the promotional video is used to update the timer before the end of the show promotional video
}
 
- (void)onCompleteWithSection:(NSString *)section instreamAd:(MTRGInstreamAd *)instreamAd
{
   // Playback of all promotional videos in the advertising section is completed
}
 
- (void)onShowModalWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
 
- (void)onDismissModalWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
 
- (void)onLeaveApplicationWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}

Display ads

After the data has been successfully uploaded, you can start displaying ad sections.

Each partition section can contain multiple ad video, after the playing of each method will be called onBannerStart in the prescribed delegate MTRGInstreamAdDelegate, after playing each video method will be called onBannerComplete.

After the playback of all advertising videos in the running section is completed, the onComplete method will be called — this is what you should use for further actions, it will be called even if an error occurred during playback and the onError method was called.

Display of preroll and postroll sections

To display preroll section must before you start showing the video to invoke a method startPreroll instance InstreamAd.

To show the postroll section is necessary after the end of the video to call the method startPostroll.
// Before starting the main video
[_ad startPreroll];
 
// After showing the main video
[_ad startPostroll];

Showing the midroll section

To display midroll section in any position of the video, you can create an instance MTRGInstreamAd ask an array of positions, which is planned to show the midroll section.

Positions can be set in seconds or as a percentage of the video duration. After successful data loading, an array of positions for which there are promotional videos will be available. That is, if positions were set at the first and fifth seconds, and advertising videos in the downloaded data are only for the first, then only one first position will be available in the array.

If the positions were not set by the application, they will be set by the server.

If the array of positions after loading is empty, then there is no data to show the midroll section.
@interface YourViewController : UIViewController <MTRGInstreamAdDelegate>
@end
 
@implementation YourViewController
{
    MTRGInstreamAd *_ad;
    NSArray <NSNumber *> *_adPositions;
}
 
- (void)initAd
{
    // Create an instance of MTRGInstreamAd
    _ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
 
    // Set positions on the first and fifth seconds of the video
    [_ad configureMidpoints:@[@1, @5] forVideoDuration:_videoDuration];
    // or percentage, 10% and 50% video
    // [_ad configureMidpointsP:@[@10, @50] forVideoDuration:_videoDuration];
     
    // Set the delegate
    _ad.delegate = self;
  
    // Start loading data
    [_ad load];
}
  
- (void)onLoadWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
    // The data was successfully loaded
    // Array of positions (in seconds) available to display the midroll section
    _adPositions = _ad.midpoints;
}
When the main video reaches one of the positions for the midroll section, it is necessary to call the startMidroll method and pass this position to it as a parameter.
// The video was played to the 5th second and it has a position in the array adPositions
[_ad startMidrollWithPoint:_adPositions[1]];

Available ad video properties

The onBannerStart and onBannerComplete methods of the MTRGInstreamAdDelegate delegate pass an instance of MTRGInstreamAdBanner that contains information about the current promotional video that can be used by the application.
@property(nonatomic) NSTimeInterval duration;
The duration of the current promotional video in seconds.
@property(nonatomic) BOOL allowClose;
Is it allowed to close the advertising video during playback. Used to control the display of the "Close" or "Skip" button.
@property(nonatomic) NSTimeInterval allowCloseDelay;
The time in seconds after which the ad video can be closed. Used to control the display of the "Close" or "Skip" button.
@property(nonatomic) CGSize size;
The width and height of the ad video.
@property(nonatomic, copy) NSString *ctaText;
Text for call-to-action buttons.

Click processing

The application should independently track clicks on the advertising video (usually on the cta button) and call the handleClickWithController method in the MTRGInstreamAd instance to process the click and go to the advertised site or application.
- (void)onAdClick
{
    [_ad handleClickWithController:self];
}

Condition management

The following control methods are available on the MTRGInstreamAd instance.
- (void)pause;
Pauses the playback of the advertising video.
- (void)resume;
Resumes playing the promotional video.
- (void)stop;
Stops the display of the ad section.
- (void)skip;
Stops the display of the advertising section, if it was done by the user (pressing the "Skip" or "Close" button).
- (void)skipBanner;
Stops the current promotional video and moves on to the next one if it was made by the user (click on the "Skip" or "Close"button).
@property(nonatomic) float volume;
Sets the volume from 0 to 1.
@property(nonatomic) NSUInteger loadingTimeout;
Sets the timeout for loading ads in seconds. If at the expiration of the specified interval failed to get the banners will be triggered callback onNoAd. The default value is 10 seconds and the minimum value is 5 seconds.

User data

For the best selection of advertisements, you can optionally specify the gender and age of the user. If your application uses its own localization model, you can also specify the language of the selected localization in ISO 639-1 format ("ru", "en", "fr", etc.).

To set custom data, you need to use the customParams property.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGInstreamAd *_ad;
}
 
- (void)initAd
{
    // Create an instance of MTRGInstreamAd
    _ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
  
    // Set the age
    _ad.customParams.age = [NSNumber numberWithInt:25];
    // Set gender
    _ad.customParams.gender = MTRGGenderMale;
}

Samples

Examples of integration are available in our demo application on Github.

In-stream audio

myTarget SDK provides the ability to play in-stream audio ads in your app while listening to audio.

Ads can be run before audio playback (preroll), during playback (midroll), and after playback (postroll). The SDK downloads the data and gives the app the ability to play ads in the app's player.

Initialization

To play ad audio in your application, you must create an instance of the MTRGInstreamAudioAd class.

To create an instance of MTRGInstreamAudioAd, you must specify your slotId. For each audio in your application, you need to create your own instance of the MTRGInstreamAudioAd class.
@interface YourViewController : UIViewController
@end
  
@implementation YourViewController
{
  MTRGInstreamAudioAd *_ad;
}
  
- (void)initAd
{
    // Enable debug mode
    // [MTRGInstreamAudioAd setDebugMode:YES];
    // Create an instance of MTRGInstreamAudioAd
    _ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
}

Using the application player

To play ads in the application player, it must implement the MTRGInstreamAudioAdPlayer protocol and notify the delegate MTRGInstreamAudioAdPlayerDelegate set to it.

To use your player, you need to set it in the player property of the created instance MTRGInstreamAudioAd.
@interface YourViewController : UIViewController
@end
  
@implementation YourViewController
{
  MTRGInstreamAudioAd *_ad;
}
  
- (void)initAd
{
    // Create an instance of MTRGInstreamAudioAd
    _ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
      
    // Install the player
    _ad.player = YOUR_PLAYER;
}

Protocol MTRGInstreamAudioAdPlayer

The MTRGInstreamAudioAdPlayer Protocol methods are called by the MTRGInstreamAudioAd instance. You do not need to call them yourself.
@property(nonatomic, readonly) NSTimeInterval adAudioDuration;
The duration of the promotional audio
@property(nonatomic, readonly) NSTimeInterval adAudioTimeElapsed;
Current position of promotional audio. The method is called multiple times during ad audio playback and should return the actual value in seconds.
@property(nonatomic, weak) id <MTRGInstreamAudioAdPlayerDelegate> adPlayerDelegate;
Sets a listener to the player
@property(nonatomic) float volume;
Current context
void setVolume(float volume);
Sets the volume from 0 to 1
- (void)playAdAudioWithUrl:(NSURL *)url;
Starts the playback of audio advertising.

uri — the path to the audio
- (void)pauseAdAudio;
Pauses the playback of audio advertising.
- (void)resumeAdAudio;
Resumes the playback of audio advertising.
- (void)stopAdAudio;
Stops the playback of audio advertising.

Protocol MTRGInstreamAudioAdPlayerDelegate

The MTRGInstreamAudioAdPlayerDelegate Protocol callback methods for the installed delegate must be called by the player in response to calls to the MTRGInstreamAudioAdPlayer Protocol methods when certain events occur.
- (void)onAdAudioStart;
Method should be invoked after a successful start of playback of audio advertising, as a response to the call playAdAudioWithUrl.
- (void)onAdAudioPause;
The method should be called after pausing ad audio playback as a response to a call to the pauseAdAudio method.
- (void)onAdAudioResume;
Method should be invoked after the resumption of the playback of audio advertising, as a response to the call resumeAdAudio.
- (void)onAdAudioStop;
The method should be called after stopping the playback of advertising audio, as an answer to the stopAdAAudio method call.
- (void)onAdAudioErrorWithReason:(NSString *)reason;
The method must be called when any error occurs when playing advertising audio.
- (void)onAdAudioComplete;
The method must be called when the ad audio has been played.

Download ads

To receive notifications (such as a successful data download or a download error), you must install the MTRGInstreamAudioAd delegate that implements the MTRGInstreamAudioAdDelegate Protocol on the created instance, and then you can start the data download.
interface YourViewController : UIViewController <MTRGInstreamAudioAdDelegate>
@end
  
@implementation YourViewController
{
  MTRGInstreamAudioAd *_ad;
}
  
- (void)initAd
{
    // Create an instance of MTRGInstreamAudioAd
    _ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
      
    // Set the delegate
    _ad.delegate = self;
  
    // Start loading data
    [_ad load];
}
  
- (void)onLoadWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // The data was successfully loaded
}
  
- (void)onNoAdWithReason:(NSString *)reason instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // No data received
}
  
- (void)onErrorWithReason:(NSString *)reason instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // An error occurred while playing the promotional video
}
  
- (void)onBannerStart:(MTRGInstreamAudioAdBanner *)banner instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // Began playing the promotional video
}
  
- (void)onBannerComplete:(MTRGInstreamAudioAdBanner *)banner instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // Ad video playback completed
}
  
- (void)onBannerTimeLeftChange:(NSTimeInterval)timeLeft duration:(NSTimeInterval)duration instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // Is called multiple times during playback of the promotional video is used to update the timer before the end of the show promotional video
}
  
- (void)onCompleteWithSection:(NSString *)section instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
   // Playback of all promotional videos in the advertising section is completed
}
  
- (void)onShowModalWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
}
  
- (void)onDismissModalWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
}
  
- (void)onLeaveApplicationWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
}

Playing ads

After the data has been successfully uploaded, you can start playing ad sections. Each section can contain several advertising audio, after the playback of each section will be called onBannerStart method in the installed delegate MTRGInstreamAudioAdDelegate, after the playback of each audio method will be called onBannerComplete.

After the playback of all advertising audio in the running section is completed, the onComplete method will be called — this is what you should use for further actions. It will be called even if an error occurred during playback and the onError method was called.

Display of preroll and postroll sections

For playing preroll section before playing audio to invoke a method startPreroll instance MTRGInstreamAudioAd.

To play the postroll section is necessary after the audio call method startPostroll.
// Before starting the main video
[_ad startPreroll];
  
// After showing the main video
[_ad startPostroll];

Showing the midroll section

To play the midroll section in some audio position, after creating an instance of MTRGInstreamAudioAd, set an array of positions at which you plan to play the midroll section. Positions can be set in seconds or as a percentage of the audio duration.

After successful data loading, an array of positions for which there is advertising audio will be available. That is, if positions were set at the first and fifth seconds, and advertising audio in the loaded data is only for the first, then there will be only one first position in the available array. If the positions were not set by the application, they will be set by the server.

If the array of positions after loading is empty, then there is no data for playing the midroll section.
@interface YourViewController : UIViewController <MTRGInstreamAudioAdDelegate>
@end
  
@implementation YourViewController
{
    MTRGInstreamAudioAd *_ad;
    NSArray <NSNumber *> *_adPositions;
}
  
- (void)initAd
{
    // Создаем экземпляр MTRGInstreamAudioAd
    _ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
  
    // Set positions on the first and fifth second of audio
    [_ad configureMidpoints:@[@1, @5] forVideoDuration:_videoDuration];
    // or percentage, 10% and 50% audio
    // [_ad configureMidpointsP:@[@10, @50] forVideoDuration:_videoDuration];
      
    // Set the delegate
    _ad.delegate = self;
   
    // Start loading data
    [_ad load];
}
   
- (void)onLoadWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
    // The data was successfully loaded
    // Array of positions (in seconds) available to display the midroll section
    _adPositions = _ad.midpoints;
}
When the main audio reaches one of the positions for the midroll section, it is necessary to call the startMidroll method and pass this position to it as a parameter.
// Audio play to 5 seconds and there position in the array adPositions
[_ad startMidrollWithPoint:_adPositions[1]];

Available ad audio properties

The onBannerStart and onBannerComplete methods of the MTRGInstreamAudioAdDelegate delegate are passed an instance of MTRGInstreamAudioAdBanner that contains information about the current ad audio that can be used by the application.
@property(nonatomic) NSTimeInterval duration;
The duration of the current ad audio in seconds.
@property(nonatomic) BOOL allowSeek;
Is it allowed to scroll through audio advertising.
@property(nonatomic) BOOL allowSkip;
Is it allowed to skip ad audio.
@property(nonatomic) BOOL allowTrackChange;
Is it allowed to move to the next track.
@property(nonatomic) NSArray<MTRGInstreamAdCompanionBanner *> *companionBanners;
List of companion banners.
@property(nonatomic, copy) NSString *adText;
Promotional text.

Companion banners

The application should independently monitor impressions and clicks on companion banners and call the handleCompanionShow and handleCompanionClick methods in the MTRGInstreamAudioAd instance to process the display and click and go to the advertised site or application.
- (void)onCompanionAdShow:(MTRGInstreamAdCompanionBanner *)companionBanner
{
    [_ad handleCompanionShow:companionBanner];
}
 
- (void)onCompanionAdClick:(MTRGInstreamAdCompanionBanner *)companionBanner
{
    [_ad handleCompanionClick:companionBanner withController:self];
}

Condition management

The following control methods are available on the MTRGInstreamAudioAd instance.
- (void)pause;
Pauses the playback of ad audio.
- (void)resume;
Resumes playing advertising audio.
- (void)stop;
Stops the advertising section.
- (void)skip;
Stops the advertising section display if it was done by the user (clicking on the "Skip" or "Close" button).
- (void)skipBanner;
Stops the current ad audio and proceeds to the next if it was done by the user (clicking on the "Skip" or "Close" button).
@property(nonatomic) float volume;
Sets the volume from 0 to 1.
@property(nonatomic) NSUInteger loadingTimeout;
Sets the timeout for advertising loading in seconds. In case if after the expiration of the specified interval it was not possible to get banners, the onNoAd callback will be called. The default is 10 seconds, the minimum is 5 seconds.

User Data

For a better selection of advertisements, you can additionally specify the gender and age of the user. If your application uses its own localization model, you can also specify the language of the selected localization in ISO 639-1 format ("ru", "en", "fr", etc.).

To set user data, you need to use the customParams property.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGInstreamAudioAd *_ad;
}
 
-(void) initAd
{
    // Create an instance of MTRGInstreamAudioAd
    _ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
  
    // Set age
    _ad.customParams.age = [NSNumber numberWithInt:25];
    // Set gender
    _ad.customParams.gender = MTRGGenderMale;
}

Samples

Integration examples are available in our demo application on Github.
Was this article helpful?
Yes
No