У меня есть встроенный Google IMA sdk для моего проекта с использованием cocoapods (pod 'GoogleAds-IMA-iOS-SDK', '~> 3.2.1'). У меня есть отдельный класс под названием VideoPresenter для взаимодействия с sdk. Этот презентатор является свойством ячейки коллекции, называемой VideoCell, которая использует AVPlayer для воспроизведения некоторого видеоконтента (я пытаюсь добавить видеоролики preroll к этому видеоконтенту). Загрузчик объявлений всегда терпит неудачу с сообщением об ошибке «Время загрузки IMA SDK». Как это исправить? Ниже приведен код для ведущего:Ошибка загрузчика google ima sdk с тайм-аутом sdk
#import "VideoAdPresenter.h"
#import <GoogleInteractiveMediaAds/GoogleInteractiveMediaAds.h>
@interface VideoAdPresenter() <IMAAdsLoaderDelegate, IMAAdsManagerDelegate>
@property (nonatomic, strong) IMAAVPlayerContentPlayhead *contentPlayhead;
@property (nonatomic, strong) IMAAdsLoader *adsLoader;
@property (nonatomic, strong) IMAAdsManager *adsManager;
@end
NSString *const kTestAppAdTagUrl =
@"https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=";
@implementation VideoAdPresenter
- (id)initWithAvPlayer:(AVPlayer *)anAvPlayer
{
self = [super init];
if(self) {
self.contentPlayhead = [[IMAAVPlayerContentPlayhead alloc]initWithAVPlayer:anAvPlayer];
[self setupAdsLoader];
}
return self;
}
- (void)setupAdsLoader
{
self.adsLoader = [[IMAAdsLoader alloc] initWithSettings:nil];
self.adsLoader.delegate = self;
}
- (void)requestAds {
if(!self.videoAdTagUrl || [self.videoAdTagUrl isEqualToString:@""]) {
NSLog(@"Nil or empty video ad tag url (%@) passed to video ad presenter: %@", self.videoAdTagUrl, [self description]);
return;
}
IMAAdDisplayContainer *adDisplayContainer = [[IMAAdDisplayContainer alloc] initWithAdContainer:self.adContainerView companionSlots:nil];
IMAAdsRequest *request = [[IMAAdsRequest alloc]initWithAdTagUrl:kTestAppAdTagUrl adDisplayContainer:adDisplayContainer contentPlayhead:self.contentPlayhead userContext:nil];
[self.adsLoader requestAdsWithRequest:request];
}
#pragma mark - ads loader delegate
- (void)adsLoader:(IMAAdsLoader *)loader adsLoadedWithData: (IMAAdsLoadedData *)adsLoadedData {
// Grab the instance of the IMAAdsManager and set ourselves as the delegate.
self.adsManager = adsLoadedData.adsManager;
self.adsManager.delegate = self;
IMAAdsRenderingSettings *adsRenderingSettings = [[IMAAdsRenderingSettings alloc] init];
adsRenderingSettings.webOpenerPresentingController = self.presentingController;
[self.adsManager initializeWithAdsRenderingSettings:adsRenderingSettings];
}
- (void)adsLoader:(IMAAdsLoader *)loader failedWithErrorData: (IMAAdLoadingErrorData *)adErrorData {
// Something went wrong loading ads. Log the error and play the content.
NSLog(@"Error loading ads: %@", adErrorData.adError.message);
if(self.delegate && [self.delegate respondsToSelector:@selector(videoAdPresenterRequestedContentResume:)]) {
[self.delegate videoAdPresenterRequestedContentResume:self];
}
}
#pragma mark - ads manager delegate
- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdEvent: (IMAAdEvent *)event {
// When the SDK notified us that ads have been loaded, play them.
if (event.type == kIMAAdEvent_LOADED) {
[adsManager start];
}
}
- (void)adsManager:(IMAAdsManager *)adsManager didReceiveAdError:(IMAAdError *)error {
// Something went wrong with the ads manager after ads were loaded. Log the error and play the
// content.
NSLog(@"AdsManager error: %@", error.message);
if(self.delegate && [self.delegate respondsToSelector:@selector(videoAdPresenterRequestedContentResume:)]) {
[self.delegate videoAdPresenterRequestedContentResume:self];
}
}
- (void)adsManagerDidRequestContentPause:(IMAAdsManager *)adsManager {
// The SDK is going to play ads, so pause the content.
if(self.delegate && [self.delegate respondsToSelector:@selector(videoAdPresenterRequestedContentPause:)]) {
[self.delegate videoAdPresenterRequestedContentPause:self];
}
}
- (void)adsManagerDidRequestContentResume:(IMAAdsManager *)adsManager {
// The SDK is done playing ads (at least for now), so resume the content.
if(self.delegate && [self.delegate respondsToSelector:@selector(videoAdPresenterRequestedContentResume:)]) {
[self.delegate videoAdPresenterRequestedContentResume:self];
}
}
@end