@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGNativeBannerAd *_ad;
}
- (void)initAd
{
// Включение режима отладки
// [MTRGNativeBannerAd setDebugMode:YES];
// Создаем экземпляр MTRGNativeAd
_ad = [MTRGNativeBannerAd nativeBannerAdWithSlotId:YOUR_SLOT_ID];
}
@interface YourViewController : UIViewController <MTRGNativeBannerAdDelegate>
@end
@implementation YourViewController
{
MTRGNativePromoAd *_ad;
}
- (void)initAd
{
// Создаем экземпляр MTRGNativeAd
_ad = [MTRGNativeBannerAd nativeBannerAdWithSlotId:YOUR_SLOT_ID];
// Устанавливаем делегат
_ad.delegate = self;
// Запускаем загрузку данных
[_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];
- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
// Заголовок рекламного объявления
NSString *title = banner.title;
// Возрастное ограничение. Может быть nil
NSString *ageRestrictions = banner.ageRestrictions;
// Дисклеймер. Может быть nil
NSString *disclaimer = banner.disclaimer;
// Текст метки "Реклама"
NSString *advertisingLabel = banner.advertisingLabel;
// Иконка
MTRGImageData *icon = banner.icon;
// Текст действия для кнопки
NSString *ctaText = banner.ctaText;
// Свойства, доступные только для объявлений, рекламирующих приложения
if (banner.navigationType == MTRGNavigationTypeStore))
{
// Рейтинг приложения (0-5)
NSNumber *rating = banner.rating;
// Количество оценок
NSUInteger votes = banner.votes;
}
// Свойства, доступные только для объявлений, рекламирующих сайты
else if (banner.navigationType == MTRGNavigationTypeWeb)
{
// Домен сайта
NSString *domain = banner.domain;
}
// Пример заполнения визуального компонента
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:iconAdView];
[adView addSubview:ctaButton];
MTRGNativeAdContainer *containerView = [MTRGNativeAdContainer createWithAdView:adView];
containerView.titleView = titleLabel;
containerView.iconView = iconAdView;
containerView.ctaView = ctaButton;
// Регистрируем визуальный компонент
[nativeBannerAd registerView:containerView withController:self];
// Добавляем на экран
[self.view addSubview:containerView];
}
...
_ad.adChoicesPlacement = MTRGAdChoicesPlacementTopRight;
[_ad load];
- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
...
...
...
// Регистрируем визуальный компонент, с кликабельными заголовком и кнопкой призыва к действию
[nativeBannerAd registerView:adView withController:self withClickableViews:@[titleLabel, ctaButton]];
// Добавляем на экран
[self.view addSubview:adView];
}
- (void)onLoadWithNativeBanner:(MTRGNativeBanner *)banner nativeBannerAd:(MTRGNativeBannerAd *)nativeBannerAd
{
// Создаем визуальный компонент
MTRGNativeBannerAdView *adView = [MTRGNativeViewsFactory createNativeBannerAdView];
adView.banner = banner;
// Доступные для настройки внутренние визуальные компоненты
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;
// Отступы
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;
// Регистрируем визуальный компонент
[nativeBannerAd registerView:adView withController:self];
// Добавляем на экран
[self.view addSubview:adView];
}
// Включение режима отладки
// [MTRGNativeBannerAdLoader setDebugMode:YES];
// Создаем MTRGNativeBannerAdLoader
MTRGNativeBannerAdLoader *nativeBannerAdLoader = [MTRGNativeBannerAdLoader loaderForCount:COUNT slotId:YOUR_SLOT_ID];
// Загружаем баннеры
[nativeBannerAdLoader loadWithCompletionBlock:^(NSArray<MTRGNativeBannerAd *> * _Nonnull nativeBannerAds)
{
for (MTRGNativeBannerAd *nativeBannerAd in nativeBannerAds)
{
// Устанавливаем делегат
nativeBannerAd.delegate = self;
MTRGNativeBanner *banner = nativeBannerAd.banner;
// Код, аналогичный методу onLoadWithNativeBanner протокола MTRGNativeBannerAdDelegate
}
}];