With a few changes to your code, you can combine native and banner ads in your ad requests.
پیشنیازها
- Version 7.20.0 or higher of Google Mobile Ads SDK .
- کیت توسعه Google Mobile Ads SDK را راهاندازی کنید .
بارگیری یک تبلیغ
تبلیغات بومی رندر شده سفارشی از طریق اشیاء GADAdLoader بارگذاری میشوند. شیء GADAdLoader همچنین میتواند طوری پیکربندی شود که درخواستهای تبلیغاتی را ایجاد کند که میتواند منجر به یک بنر یا تبلیغ بومی شود. اضافه کردن GADAdLoaderAdTypeGAMBanner به پارامتر آرایه adTypes ، همراه با انواع تبلیغات بومی مانند GADAdLoaderAdTypeNative هنگام ایجاد شیء GADAdLoader ، مشخص میکند که تبلیغات بنری باید برای پر کردن درخواست با تبلیغات بومی رقابت کنند.
سویفت
adLoader = GADAdLoader(adUnitID: "/21775744923/example/native-and-banner", rootViewController: self, adTypes: [.native, .gamBanner], options: [... ad loader options objects ...]) adLoader.delegate = self
هدف-سی
self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"/21775744923/example/native-and-banner" rootViewController:rootViewController adTypes:@[ GADAdLoaderAdTypeNative, GADAdLoaderAdTypeGAMBanner ] options:@[ ... ad loader options objects ... ]]; self.adLoader.delegate = self;
نماینده GAMBannerAdLoader
هنگام درخواست تبلیغات بنری از طریق GADAdLoader ، نمایندهی بارگذاری تبلیغات باید با پروتکل GAMBannerAdLoaderDelegate مطابقت داشته باشد. این پروتکل شامل پیامی است که هنگام بارگذاری یک بنر تبلیغاتی ارسال میشود:
سویفت
public func adLoader(_ adLoader: GADAdLoader, didReceive GAMBannerView: GAMBannerView)
هدف-سی
- (void)adLoader:(GADAdLoader *)adLoader didReceiveGAMBannerView:(GAMBannerView *)bannerView;
The ad loader delegate must also specify which banner ad sizes should be requested by responding to the validBannerSizesForAdLoader message as shown below.
سویفت
public func validBannerSizes(for adLoader: GADAdLoader) -> [NSValue] { return [NSValueFromGADAdSize(GADAdSizeBanner), NSValueFromGADAdSize(GADAdSizeMediumRectangle), NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSize(width: 120, height: 20)))] }
هدف-سی
- (NSArray*)validBannerSizesForAdLoader:(GADAdLoader *)adLoader { return @[ @(GADAdSizeBanner), @(GADAdSizeMediumRectangle), @(GADAdSizeFromCGSize(CGSizeMake(120, 20))) ]; }
شمارش دستی برداشت
To enable manual impression counting on banner ads loaded through GADAdLoader , set a GAMBannerViewOptions with enableManualImpressions set to YES when initializing GADAdLoader .
سویفت
let bannerViewOptions = GAMBannerViewOptions() bannerViewOptions.enableManualImpressions = true adLoader = GADAdLoader( adUnitID: "/21775744923/example/native-and-banner", rootViewController: self, adTypes: [.native, .gamBanner], options: [bannerViewOptions])
هدف-سی
GAMBannerViewOptions *bannerViewOptions = [[GAMBannerViewOptions alloc] init]; bannerViewOptions.enableManualImpressions = YES; self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"/21775744923/example/native-and-banner" rootViewController:self adTypes:@[ GADAdLoaderAdTypeNative, GADAdLoaderAdTypeGAMBanner ] options:@[ bannerViewOptions ]];
If a banner ad loads, you can call recordManualImpression when you determine that an ad has been successfully returned and is on-screen to manually fire an impression:
سویفت
bannerView.recordImpression()
هدف-سی
[self.bannerView recordImpression];