@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGAdView *_adView;
}
- (void)initAd
{
// Enabling debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGAdView, adaptive format
_adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID];
// 300x250 format
// _adView.adSize = [MTRGAdSize adSize300x250];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
_adView.adSize = [MTRGAdSize adSizeForCurrentOrientation];
}
+ (instancetype)adSize320x50;
+ (instancetype)adSize300x250;
+ (instancetype)adSize728x90;
+ (instancetype)adSizeForCurrentOrientation; // Adaptive
+ (instancetype)adSizeForCurrentOrientationForWidth:(CGFloat)width; // Adaptive with maximum width restriction
@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
{
}
// Disable automatic ad rotation
_adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID shouldRefreshAd:NO];
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInterstitialAd *_ad;
}
- (void)initAd
{
// Enabling debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGInterstitialAd
_ad = [MTRGInterstitialAd interstitialAdWithSlotId:YOUR_SLOT_ID];
}
@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
{
}
- (void)onLoadWithInterstitialAd:(MTRGInterstitialAd *)interstitialAd
{
[_ad showWithController:self];
}
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGRewardedAd *_ad;
}
- (void)initAd
{
// Enabling debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGRewardedAd
_ad = [MTRGRewardedAd rewardedAdWithSlotId:YOUR_SLOT_ID];
}
@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
{
}
- (void)onLoadWithRewardedAd:(MTRGRewardedAd *)rewardedAd
{
[_ad showWithController:self];
}
@property(nonatomic, readonly) NSString *type;
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGNativeAd *_ad;
}
- (void)initAd
{
// Enabling debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGNativeAd
_ad = [MTRGNativeAd nativeAdWithSlotId:YOUR_SLOT_ID];
}
@interface YourViewController : UIViewController <MTRGNativeAdDelegate>
@end
@implementation YourViewController
{
MTRGNativePromoAd *_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
{
}
_ad.cachePolicy = MTRGCachePolicyNone;
[_ad load];
@protocol MTRGNativeAdMediaDelegate <NSObject>
- (void)onIconLoadWithNativeAd:(MTRGNativeAd *)nativeAd;
- (void)onImageLoadWithNativeAd:(MTRGNativeAd *)nativeAd;
- (void)onAdChoicesIconLoadWithNativeAd:(MTRGNativeAd *)nativeAd;
- (void)onMediaLoadFailedWithNativeAd:(MTRGNativeAd *)nativeAd;
@end
- (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];
}
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);
}
...
_ad.adChoicesPlacement = MTRGAdChoicesPlacementTopRight;
[_ad load];
- (void)setupAdChoicesView
{
_ad.adChoicesPlacement = MTRGAdChoicesPlacementManual;
MTRGAdChoicesView *adChoicesView = MTRGNativeViewsFactory.createAdChoicesView;
// Set your picture
adChoicesView.imageView.image = [UIImage imageNamed:@"AdChoices"];
[_adView addSubview:adChoicesView];
// You can use Autolayout or frames to position and size adChoicesView
}
- (void)setupAdChoicesView
{
_ad.adChoicesPlacement = MTRGAdChoicesPlacementDrawingManual;
_adChoicesButton = UIButton.new;
[_adChoicesButton setImage:_ad.banner.adChoicesIcon.image forState:UIControlStateNormal];
[_adChoicesButton addTarget:self action:@selector(adChoicesClick) forControlEvents:UIControlEventTouchUpInside];
[_adView addSubview:_adChoicesButton];
// You can use Autolayout or frames to position and size adChoicesImageView
}
// Notify SDK that the AdChoices component has been clicked
- (void)adChoicesClick
{
[_ad handleAdChoicesClickWithController:self sourceView:_adChoicesButton];
}
- (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];
}
// Example of menu implementation
// Add MTRGMenuAction model to _items. An array of objects to be shown in the menu
- (void)addMenuAction:(nonnull MTRGMenuAction *)action
{
[_items addObject:action];
}
// Based on _items, create a UIAlertController and display it
- (void)presentInViewController:(nonnull UIViewController *)viewController sourceView:(nullable UIView *)sourceView
{
UIAlertControllerStyle style = UIAlertControllerStyleAlert;
MTRGAlertController *alert = [MTRGAlertController alertControllerWithTitle:nil message:nil preferredStyle:style];
for (MTRGMenuAction *item in _items.copy)
{
UIAlertActionStyle actionStyle = (item.style == MTRGMenuActionStyleDefault) ? UIAlertActionStyleDefault : UIAlertActionStyleCancel;
UIAlertAction *action = [UIAlertAction actionWithTitle:item.title
style:actionStyle
handler:^(UIAlertAction * _Nonnull action)
{
[item handleClick];
}];
[alert addAction:action];
}
[viewController presentViewController:alert animated:YES completion:nil];
}
- (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];
}
// 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
}
}];
// Enable debug mode
// [MTRGManager setDebugMode:YES];
// Creating MTRGNativeAdLoader
MTRGNativeAdLoader *nativeAdLoader = [MTRGNativeAdLoader loaderForCount:COUNT slotId:YOUR_SLOT_ID];
// Loading banners
[nativeAdLoader loadWithCompletionBlock:^(NSArray<MTRGNativeAd *> * _Nonnull nativeAds)
{
for (MTRGNativeAd *nativeAd in nativeAds)
{
// Installing the delegate
nativeAd.delegate = self;
MTRGNativePromoBanner *promoBanner = nativeAd.banner;
// Code similar to protocol MTRGNativeAdDelegate method onLoadWithNativePromoBanner
}
}];
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGNativeBannerAd *_ad;
}
- (void)initAd
{
// Enabling debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGNativeAd
_ad = [MTRGNativeBannerAd nativeBannerAdWithSlotId:YOUR_SLOT_ID];
}
@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
{
}
_ad.cachePolicy = MTRGCachePolicyNone;
[_ad load];
@protocol MTRGNativeBannerAdMediaDelegate <NSObject>
- (void)onIconLoadWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd;
- (void)onAdChoicesIconLoadWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd;
- (void)onMediaLoadFailedWithNativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd;
@end
- (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];
}
...
_ad.adChoicesPlacement = MTRGAdChoicesPlacementTopRight;
[_ad load];
- (void)setupAdChoicesView
{
_ad.adChoicesPlacement = MTRGAdChoicesPlacementManual;
MTRGAdChoicesView *adChoicesView = MTRGNativeViewsFactory.createAdChoicesView;
// Set your picture
adChoicesView.imageView.image = [UIImage imageNamed:@"AdChoices"];
[_adView addSubview:adChoicesView];
// You can use Autolayout or frames to position and size adChoicesView
}
- (void)setupAdChoicesView
{
_ad.adChoicesPlacement = MTRGAdChoicesPlacementDrawingManual;
_adChoicesButton = UIButton.new;
[_adChoicesButton setImage:_ad.banner.adChoicesIcon.image forState:UIControlStateNormal];
[_adChoicesButton addTarget:self action:@selector(adChoicesClick) forControlEvents:UIControlEventTouchUpInside];
[_adView addSubview:_adChoicesButton];
// You can use Autolayout or frames to position and size adChoicesImageView
}
// Notify SDK that the AdChoices component has been clicked
- (void)adChoicesClick
{
[_ad handleAdChoicesClickWithController:self sourceView:_adChoicesButton];
}
- (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];
}
// Example of menu implementation
// Add MTRGMenuAction model to _items. An array of objects to be shown in the menu
- (void)addMenuAction:(nonnull MTRGMenuAction *)action
{
[_items addObject:action];
}
// Based on _items, create a UIAlertController and display it
- (void)presentInViewController:(nonnull UIViewController *)viewController sourceView:(nullable UIView *)sourceView
{
UIAlertControllerStyle style = UIAlertControllerStyleAlert;
MTRGAlertController *alert = [MTRGAlertController alertControllerWithTitle:nil message:nil preferredStyle:style];
for (MTRGMenuAction *item in _items.copy)
{
UIAlertActionStyle actionStyle = (item.style == MTRGMenuActionStyleDefault) ? UIAlertActionStyleDefault : UIAlertActionStyleCancel;
UIAlertAction *action = [UIAlertAction actionWithTitle:item.title
style:actionStyle
handler:^(UIAlertAction * _Nonnull action)
{
[item handleClick];
}];
[alert addAction:action];
}
[viewController presentViewController:alert animated:YES completion:nil];
}
- (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];
}
// Enabling debug mode
// [MTRGManager 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
}
}];
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Enable debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
}
@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;
}
@property(nonatomic, readonly) NSTimeInterval adVideoDuration;
@property(nonatomic, readonly) NSTimeInterval adVideoTimeElapsed;
@property(nonatomic, weak) id <MTRGInstreamAdPlayerDelegate> adPlayerDelegate;
@property(nonatomic, readonly) UIView *adPlayerView;
@property(nonatomic) float volume;
- (void)playAdVideoWithUrl:(NSURL *)url;
- (void)pauseAdVideo;
- (void)resumeAdVideo;
- (void)stopAdVideo;
- (void)onAdVideoStart;
- (void)onAdVideoPause;
- (void)onAdVideoResume;
- (void)onAdVideoStop;
- (void)onAdVideoErrorWithReason:(NSString *)reason;
- (void)onAdVideoComplete;
@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];
}
@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
{
}
// Before starting the main video
[_ad startPreroll];
// After showing the main video
[_ad startPostroll];
@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;
}
// The video was played to the 5th second and it has a position in the array adPositions
[_ad startMidrollWithPoint:_adPositions[1]];
@property(nonatomic) NSTimeInterval duration;
@property(nonatomic) BOOL allowClose;
@property(nonatomic) NSTimeInterval allowCloseDelay;
@property(nonatomic) CGSize size;
@property(nonatomic, copy) NSString *ctaText;
- (void)onAdClick
{
[_ad handleClickWithController:self];
}
// manually add the AdChoices display component
- (void)setupAdChoicesView
{
_adChoicesButton = UIButton.new;
[_adChoicesButton addTarget:self action:@selector(adChoicesClick) forControlEvents:UIControlEventTouchUpInside];
[_adChoicesButton setHidden:YES];
[_playerView addSubview:_adChoicesButton];
}
// inform SDK that AdChoices has been clicked
- (void)adChoicesClick
{
[_ad handleAdChoicesClickWithController:self sourceView:_adChoicesButton];
}
// Displaying the AdChoices component when the banner starts playing
- (void)onBannerStart:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
BOOL hasAdChocies = banner.adChoicesImage != nil && banner.hasAdChoices;
[_adChoicesButton setImage:banner.adChoicesImage forState:UIControlStateNormal];
_adChoicesButton.hidden = !hasAdChocies;
}
// If the user has selected the option to close ads, then skip the ads
- (void)onBannerShouldClose:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
[_ad skipBanner];
}
// Example of menu implementation
// Add MTRGMenuAction model to _items. An array of objects to be shown in the menu
- (void)addMenuAction:(nonnull MTRGMenuAction *)action
{
[_items addObject:action];
}
// Based on _items, create a UIAlertController and display it
- (void)presentInViewController:(nonnull UIViewController *)viewController sourceView:(nullable UIView *)sourceView
{
UIAlertControllerStyle style = UIAlertControllerStyleAlert;
MTRGAlertController *alert = [MTRGAlertController alertControllerWithTitle:nil message:nil preferredStyle:style];
for (MTRGMenuAction *item in _items.copy)
{
UIAlertActionStyle actionStyle = (item.style == MTRGMenuActionStyleDefault) ? UIAlertActionStyleDefault : UIAlertActionStyleCancel;
UIAlertAction *action = [UIAlertAction actionWithTitle:item.title
style:actionStyle
handler:^(UIAlertAction * _Nonnull action)
{
[item handleClick];
}];
[alert addAction:action];
}
[viewController presentViewController:alert animated:YES completion:nil];
}
- (void)pause;
- (void)resume;
- (void)stop;
- (void)skip;
- (void)skipBanner;
@property(nonatomic) float volume;
@property(nonatomic) NSUInteger loadingTimeout;
@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;
}
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAudioAd *_ad;
}
- (void)initAd
{
// Enable debug mode
// [MTRGManager setDebugMode:YES];
// Create an instance of MTRGInstreamAudioAd
_ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
}
@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;
}
@property(nonatomic, readonly) NSTimeInterval adAudioDuration;
@property(nonatomic, readonly) NSTimeInterval adAudioTimeElapsed;
@property(nonatomic, weak) id <MTRGInstreamAudioAdPlayerDelegate> adPlayerDelegate;
@property(nonatomic) float volume;
void setVolume(float volume);
- (void)playAdAudioWithUrl:(NSURL *)url;
- (void)pauseAdAudio;
- (void)resumeAdAudio;
- (void)stopAdAudio;
- (void)onAdAudioStart;
- (void)onAdAudioPause;
- (void)onAdAudioResume;
- (void)onAdAudioStop;
- (void)onAdAudioErrorWithReason:(NSString *)reason;
- (void)onAdAudioComplete;
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
{
}
// Before starting the main video
[_ad startPreroll];
// After showing the main video
[_ad startPostroll];
@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;
}
// Audio play to 5 seconds and there position in the array adPositions
[_ad startMidrollWithPoint:_adPositions[1]];
@property(nonatomic) NSTimeInterval duration;
@property(nonatomic) BOOL allowSeek;
@property(nonatomic) BOOL allowSkip;
@property(nonatomic) BOOL allowTrackChange;
@property(nonatomic) NSArray<MTRGInstreamAdCompanionBanner *> *companionBanners;
@property(nonatomic, copy) NSString *adText;
- (void)onCompanionAdShow:(MTRGInstreamAdCompanionBanner *)companionBanner
{
[_ad handleCompanionShow:companionBanner];
}
- (void)onCompanionAdClick:(MTRGInstreamAdCompanionBanner *)companionBanner
{
[_ad handleCompanionClick:companionBanner withController:self];
}
- (void)pause;
- (void)resume;
- (void)stop;
- (void)skip;
- (void)skipBanner;
@property(nonatomic) float volume;
@property(nonatomic) NSUInteger loadingTimeout;
// Adding the AdChoices component
- (void)setupAdChoicesView
{
_adChoicesButton = UIButton.new;
[_adChoicesButton addTarget:self action:@selector(adChoicesClick) forControlEvents:UIControlEventTouchUpInside];
[_adChoicesButton setHidden:YES];
[_playerView addSubview:_adChoicesButton];
}
// Click processing
- (void)adChoicesClick
{
[_ad handleAdChoicesClickWithController:self sourceView:_adChoicesButton];
}
// Displaying the AdChoices component when playing a banner
- (void)onBannerStart:(MTRGInstreamAudioAdBanner *)banner instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
BOOL hasAdChocies = banner.adChoicesImage != nil && banner.hasAdChoices;
[_adChoicesButton setImage:banner.adChoicesImage forState:UIControlStateNormal];
_adChoicesButton.hidden = !hasAdChocies;
}
// Closing of advertising
- (void)onBannerShouldClose:(MTRGInstreamAudioAdBanner *)banner instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
[_ad skipBanner];
}
// Example of menu implementation
// Добавляем модель MTRGMenuAction в _items (массив объектов, которые нужно будет показать в меню)
- (void)addMenuAction:(nonnull MTRGMenuAction *)action
{
[_items addObject:action];
}
// Create a UIAlertController based on _items and display it
- (void)presentInViewController:(nonnull UIViewController *)viewController sourceView:(nullable UIView *)sourceView
{
UIAlertControllerStyle style = UIAlertControllerStyleAlert;
MTRGAlertController *alert = [MTRGAlertController alertControllerWithTitle:nil message:nil preferredStyle:style];
for (MTRGMenuAction *item in _items.copy)
{
UIAlertActionStyle actionStyle = (item.style == MTRGMenuActionStyleDefault) ? UIAlertActionStyleDefault : UIAlertActionStyleCancel;
UIAlertAction *action = [UIAlertAction actionWithTitle:item.title
style:actionStyle
handler:^(UIAlertAction * _Nonnull action)
{
[item handleClick];
}];
[alert addAction:action];
}
[viewController presentViewController:alert animated:YES completion:nil];
}
@property (nonatomic) id <MTRGPromoCardSliderStateProtocol> sliderState;
+ (MTRGPromoCardCollectionView *)createPromoCardCollectionView;
+ (MTRGPromoCardCollectionView *)createPromoCardCollectionViewWithCardScaleFactor:(CGFloat)cardScaleFactor
cardSpacing:(CGFloat)cardSpacing;
-(void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
// ...
// ...
// List of cards
NSArray<MTRGNativePromoCard *> *cards = promoBanner.cards;
// An example of filling a visual component
// ...
// ...
if(cards.count > 0)
{
// Создаем MTRGPromoCardCollectionView
MTRGPromoCardCollectionView *cardCollectionView = [MTRGNativeViewsFactory createPromoCardCollectionView];
// Set the class for the cell
[_cardCollectionView registerClass:[CardView class] forCellWithReuseIdentifier:@"CardView"];
// Installing cards
[_cardCollectionView setCards:cards];
[adView addSubview:cardCollectionView];
}
else
{
// Creating MTRGMediaAdView
MTRGMediaAdView *mediaView = [MTRGNativeViewsFactory createMediaAdView];
[adView addSubview:mediaView];
}
// Registering a visual component
[nativeAd registerView:adView withController:self];
// Adding to the screen
[self.view addSubview:adView];
}
...
...
...
// Example class for displaying one card
@interface CardView : UICollectionViewCell <MTRGPromoCardViewProtocol>
@property(nonatomic, readonly) UILabel *titleLabel;
@property(nonatomic, readonly) UILabel *descriptionLabel;
@property(nonatomic, readonly) UILabel *ctaButtonLabel;
@property(nonatomic, readonly) MTRGMediaAdView *mediaAdView;
- (CGFloat)heightWithCardWidth:(CGFloat)width;
@end
@implementation CardView
- (instancetype)init
{
self = [super init];
if (self)
{
[self setupView];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self setupView];
}
return self;
}
- (void)setupView
{
_mediaAdView = [[MTRGMediaAdView alloc] init];
_mediaAdView.clipsToBounds = YES;
[self.contentView addSubview:_mediaAdView];
_titleLabel = [[UILabel alloc] init];
[self.contentView addSubview:_titleLabel];
_descriptionLabel = [[UILabel alloc] init];
[self.contentView addSubview:_descriptionLabel];
_ctaButtonLabel = [[UILabel alloc] init];
[self.contentView addSubview:_ctaButtonLabel];
}
- (CGFloat)heightWithCardWidth:(CGFloat)width
{
...
...
return calculatedSize;
}
@end