@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Включение режима отладки
// [MTRGInstreamAd setDebugMode:YES];
// Создаем экземпляр MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
}
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Создаем экземпляр MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Устанавливаем плеер
_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 onAdVideoResumed();
- (void)onAdVideoResume;
- (void)onAdVideoStop;
- (void)onAdVideoErrorWithReason:(NSString *)reason;
- (void)onAdVideoComplete;
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Создаем экземпляр MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Устанавливаем плеер SDK
[_ad useDefaultPlayer];
// Добавляем плеер на экран
[self.view addSubview:_ad.player.adPlayerView];
}
@interface YourViewController : UIViewController <MTRGInstreamAdDelegate>
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Создаем экземпляр MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Устанавливаем делегат
_ad.delegate = self;
// Запускаем загрузку данных
[_ad load];
}
- (void)onLoadWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
// Данные успешно загружены
}
- (void)onNoAdWithReason:(NSString *)reason instreamAd:(MTRGInstreamAd *)instreamAd
{
// Данные не получены
}
- (void)onErrorWithReason:(NSString *)reason instreamAd:(MTRGInstreamAd *)instreamAd
{
// При проигрывании рекламного видео произошла ошибка
}
- (void)onBannerStart:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
// Началось проигрывание рекламного видео
}
- (void)onBannerComplete:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
// Проигрывание рекламного видео завершено
}
- (void)onBannerTimeLeftChange:(NSTimeInterval)timeLeft duration:(NSTimeInterval)duration instreamAd:(MTRGInstreamAd *)instreamAd
{
// Вызывается многократно во время воспроизведения рекламного видео, используется для обновления таймера до окончания показа рекламного видео
}
- (void)onCompleteWithSection:(NSString *)section instreamAd:(MTRGInstreamAd *)instreamAd
{
// Проигрывание всех рекламных видео в рекламной секции завершено
}
- (void)onShowModalWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
- (void)onDismissModalWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
- (void)onLeaveApplicationWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
// Перед началом показа основного видео
[_ad startPreroll];
// После показа основного видео
[_ad startPostroll];
@interface YourViewController : UIViewController <MTRGInstreamAdDelegate>
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
NSArray <NSNumber *> *_adPositions;
}
- (void)initAd
{
// Создаем экземпляр MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Устанавливаем позиции на первой и пятой секунде видео
[_ad configureMidpoints:@[@1, @5] forVideoDuration:_videoDuration];
// или в процентах, на 10% и 50% видео
// [_ad configureMidpointsP:@[@10, @50] forVideoDuration:_videoDuration];
// Устанавливаем делегат
_ad.delegate = self;
// Запускаем загрузку данных
[_ad load];
}
- (void)onLoadWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
// Данные успешно загружены
// Массив позиций (в секундах), доступных для показа midroll секции
_adPositions = _ad.midpoints;
}
// Видео доигралось до 5й секунды и для неё есть позиция в массиве 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];
}
- (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
{
// Создаем экземпляр MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Задаем возраст
_ad.customParams.age = [NSNumber numberWithInt:25];
// Задаем пол
_ad.customParams.gender = MTRGGenderMale;
}