پیشنیازها
- قالب آگهی بومی را ادغام کنید.
GADMediaContent
آگهیهای بومی دسترسی به کلاس GADMediaContent را فراهم میکنند که برای دریافت اطلاعات درباره محتوای رسانهای استفاده میشود. این محتوا میتواند ویدیو یا تصویر باشد. همچنین برای کنترل بازپخش آگهی ویدیویی و گوش دادن به رویدادهای بازپخش استفاده میشود. میتوانید ازطریق دارایی .mediaContent در آگهی به
شیء محتوای رسانهای دسترسی پیدا کنید.
این
GADMediaContent
شیء حاوی اطلاعاتی مانند نسبت ابعادی و مدت ویدیو است. تکهکد زیر نشان میدهد که چگونه نسبت ابعادی و مدت زمان آگهی بومی را دریافت کنید.
Swift
if myNativeAd.mediaContent.hasVideoContent { let mediaAspectRatio = CGFloat(myNativeAd.mediaContent.aspectRatio) let duration = myNativeAd.mediaContent.duration }
آبجکتیو-سی
if(myNativeAd.mediaContent.hasVideoContent) { CGFloat mediaAspectRatio = myNativeAd.mediaContent.aspectRatio; NSTimeInterval duration = myNativeAd.mediaContent.duration; }
GADVideoController
شیء GADMediaContent به شیء
GADVideoController
ارجاع دارد. شیء GADVideoController به ناشران اجازه میدهد به رویدادهای ویدیو پاسخ دهند.
این شیء GADVideoController را میتوانید با تماس گرفتن با
GADMediaContent.videoController دریافت کنید.
بازخوانها برای رویدادهای ویدیویی
برای مدیریت رویدادهای ویدیویی خاص، باید کلاسی بنویسید که
GADVideoControllerDelegate
پروتکل را پیادهسازی کند. روشهای پروتکل همگی اختیاری هستند.
مثال زیر نحوه پیادهسازی پروتکل نماینده را نشان میدهد:
Swift
class ViewController: NativeAdLoaderDelegate, VideoControllerDelegate { private var adLoader: AdLoader? func viewDidLoad() { super.viewDidLoad() let videoOptions = VideoOptions() videoOptions.customControlsRequested = true adLoader = AdLoader( adUnitID: "ca-app-pub-3940256099942544/3986624511", rootViewController: self, adTypes: [.native], options: [videoOptions]) adLoader?.delegate = self adLoader?.load(Request()) } func adLoader( _ adLoader: AdLoader?, didReceive nativeAd: NativeAd? ) { // Set the videoController's delegate to be notified of video events. nativeAd?.mediaContent.videoController.delegate = self } // VideoControllerDelegate methods func videoControllerDidPlayVideo(_ videoController: VideoController) { // Implement this method to receive a notification when the video controller // begins playing the ad. } func videoControllerDidPauseVideo(_ videoController: VideoController) { // Implement this method to receive a notification when the video controller // pauses the ad. } func videoControllerDidEndVideoPlayback(_ videoController: VideoController) { // Implement this method to receive a notification when the video controller // stops playing the ad. } func videoControllerDidMuteVideo(_ videoController: VideoController) { // Implement this method to receive a notification when the video controller // mutes the ad. } func videoControllerDidUnmuteVideo(_ videoController: VideoController) { // Implement this method to receive a notification when the video controller // unmutes the ad. } }
آبجکتیو-سی
@interface ViewController () <GADNativeAdLoaderDelegate, GADVideoControllerDelegate> @property(nonatomic, strong) GADAdLoader *adLoader; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init]; videoOptions.customControlsRequested = YES; self.adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/3986624511" rootViewController:self adTypes:@[ GADAdLoaderAdTypeNative ] options:@[ videoOptions ]]; self.adLoader.delegate = self; [self.adLoader loadRequest:[GADRequest request]]; } - (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativeAd { // Set the videoController's delegate to be notified of video events. nativeAd.mediaContent.videoController.delegate = self; } // GADVideoControllerDelegate methods - (void)videoControllerDidPlayVideo:(nonnull GADVideoController *)videoController { // Implement this method to receive a notification when the video controller // begins playing the ad. } - (void)videoControllerDidPauseVideo:(nonnull GADVideoController *)videoController { // Implement this method to receive a notification when the video controller // pauses the ad. } - (void)videoControllerDidEndVideoPlayback:(nonnull GADVideoController *)videoController { // Implement this method to receive a notification when the video controller // stops playing the ad. } - (void)videoControllerDidMuteVideo:(nonnull GADVideoController *)videoController { // Implement this method to receive a notification when the video controller // mutes the ad. } - (void)videoControllerDidUnmuteVideo:(nonnull GADVideoController *)videoController { // Implement this method to receive a notification when the video controller // unmutes the ad. } @end
برای راهنمایی بیشتر درباره نحوه ارائه آگهیهای بومی، خطمشیها و دستورالعملهای آگهیهای بومی را بخوانید.