این صفحه، مهاجرتهای نسخههای فعلی و قبلی SDK تبلیغات موبایلی گوگل برای iOS را پوشش میدهد. انتظار میرود نسخه ۱۲.۰.۰ در فوریه ۲۰۲۵ منتشر شود.
مهاجرت از نسخه ۱۱ به نسخه ۱۲
ارتقا به Xcode 16.0
حداقل نسخه پشتیبانی شده Xcode به 16.0 افزایش یافته است.
پشتیبانی از نامگذاری Swift
نسخه ۱۲.۰.۰ شامل تغییراتی برای پیروی از قراردادهای نامگذاری در دستورالعملهای طراحی API سوئیفت است. این تغییرات فقط سوئیفت را تحت تأثیر قرار میدهند. هیچ تغییر نامگذاری در APIهای Objective-C اعمال نشده است.
تغییرات پیشوند کلاس
تغییرات زیر در پیشوندهای کلاس ایجاد شده است:
- پیشوند
GADدر نام همه انواع حذف شد. - پیشوند
GAMرا بهAdManagerتغییر نام داد. - پیشوند
GADMبهMediationتغییر نام داد.
خطاها را برطرف کنید
بهترین راه برای حل خطاهای ناشی از این تغییرات، انجام اصلاحیهی Fix-It است.
حل اختلافات نامگذاری
برای حل تداخلهای نامگذاری، از فضای نامی که توسط ماژول ارائه شده است استفاده کنید. برای مثال، GADRequest اکنون Request نامگذاری شده است. مثال زیر فضای نامهایی از کلاس Request مربوط به Google Mobile Ads SDK را نشان میدهد:
import GoogleMobileAds
...
var request: GoogleMobileAds.Request?
فهرست دقیق تغییرات سوئیفت
جداول زیر تغییرات ایجاد شده در API های Swift را فهرست میکنند:
| نسخه ۱۱ | نسخه ۱۲ |
|---|---|
GADAdapterInitializationState | AdapterInitializationState |
GADAdChoicesPosition | AdChoicesPosition |
GADAdChoicesView | AdChoicesView |
GADAdFormat | AdFormat |
GADAdLoader | AdLoader |
GADAdLoaderAdType | AdLoaderAdType |
GADAdLoaderDelegate | AdLoaderDelegate |
GADAdMetadataDelegate | AdMetadataDelegate |
GADAdMetadataProvider | AdMetadataProvider |
GADAdNetworkExtras | AdNetworkExtras |
GADAdNetworkResponseInfo | AdNetworkResponseInfo |
GADAdReward | AdReward |
GADAdSize | AdSize |
GADAdSizeDelegate | AdSizeDelegate |
GADAdValue | AdValue |
GADAdValuePrecision | AdValuePrecision |
GADAppEventDelegate | AppEventDelegate |
GADAppOpenAd | AppOpenAd |
GADAppOpenSignalRequest | AppOpenSignalRequest |
GADAudioVideoManager | AudioVideoManager |
GADAudioVideoManagerDelegate | AudioVideoManagerDelegate |
GADBannerSignalRequest | BannerSignalRequest |
GADBannerView | BannerView |
GADBannerViewDelegate | BannerViewDelegate |
GADCustomEventExtras | CustomEventExtras |
GADCustomEventRequest | CustomEventRequest |
GADCustomNativeAd | CustomNativeAd |
GADCustomNativeAdLoaderDelegate | CustomNativeAdLoaderDelegate |
GADCustomNativeAdDelegate | CustomNativeAdDelegate |
GADDebugOptionsViewControllerDelegate | DebugOptionsViewControllerDelegate |
GADDebugOptionsViewController | DebugOptionsViewController |
GADDisplayAdMeasurement | DisplayAdMeasurement |
GADExtras | Extras |
GADFullScreenPresentingAd | FullScreenPresentingAd |
GADFullScreenContentDelegate | FullScreenContentDelegate |
GADAdapterStatus | AdapterStatus |
GADInitializationStatus | InitializationStatus |
GADInterstitialAd | InterstitialAd |
GADInterstitialSignalRequest | InterstitialSignalRequest |
GADMediaAspectRatio | MediaAspectRatio |
GADMediaContent | MediaContent |
GADMediaView | MediaView |
GADMobileAds | MobileAds |
GADMultipleAdsAdLoaderOptions | MultipleAdsAdLoaderOptions |
GADMuteThisAdReason | MuteThisAdReason |
GADNativeAd | NativeAd |
GADNativeAdLoaderDelegate | NativeAdLoaderDelegate |
GADNativeAdView | NativeAdView |
GADNativeAdCustomClickGestureOptions | NativeAdCustomClickGestureOptions |
GADNativeAdDelegate | NativeAdDelegate |
GADNativeAdImage | NativeAdImage |
GADNativeAdImageAdLoaderOptions | NativeAdImageAdLoaderOptions |
GADNativeAdInlineBehavior | NativeAdInlineBehavior |
GADNativeAdInlineBehaviorOptions | NativeAdInlineBehaviorOptions |
GADNativeAdMediaAdLoaderOptions | NativeAdMediaAdLoaderOptions |
GADNativeAdUnconfirmedClickDelegate | NativeAdUnconfirmedClickDelegate |
GADNativeAdViewAdOptions | NativeAdViewAdOptions |
GADNativeMuteThisAdLoaderOptions | NativeMuteThisAdLoaderOptions |
GADNativeSignalRequest | NativeSignalRequest |
GADPresentationError | PresentationError |
GADPublisherPrivacyPersonalizationState | PublisherPrivacyPersonalizationState |
GADQueryInfo | QueryInfo |
GADRequest | Request |
GADRequestError | RequestError |
GADRequestConfiguration | RequestConfiguration |
GADResponseInfo | ResponseInfo |
GADRewardedAd | RewardedAd |
GADRewardedSignalRequest | RewardedSignalRequest |
GADRewardedInterstitialAd | RewardedInterstitialAd |
GADRewardedInterstitialSignalRequest | RewardedInterstitialSignalRequest |
GADSearchBannerView | SearchBannerView |
GADServerSideVerificationOptions | ServerSideVerificationOptions |
GADSignal | Signal |
GADSignalRequest | SignalRequest |
GADVersionNumber | VersionNumber |
GADVideoController | VideoController |
GADVideoControllerDelegate | VideoControllerDelegate |
| مدیر تبلیغات | |
GAMBannerAdLoaderDelegate | AdManagerBannerAdLoaderDelegate |
GAMBannerView | AdManagerBannerView |
GAMBannerViewOptions | AdManagerBannerViewOptions |
GAMInterstitialAd | AdManagerInterstitialAd |
GAMRequest | AdManagerRequest |
| میانجیگری | |
GADMAdNetworkAdapter | MediationAdNetworkAdapter |
GADMAdNetworkConnector | MediationAdNetworkConnector |
GADMBannerAnimationType | MediationBannerAnimationType |
GADMediatedUnifiedNativeAd | MediationUnifiedNativeAd |
GADMediatedUnifiedNativeAdNotificationSource | MediationUnifiedNativeAdNotificationSource |
GADMediationAd | MediationAd |
GADMediationAdConfiguration | MediationAdConfiguration |
GADMediationAdEventDelegate | MediationAdEventDelegate |
GADMediationAdRequest | MediationAdRequest |
GADMediationAdapter | MediationAdapter |
GADMediationAppOpenAd | MediationAppOpenAd |
GADMediationAppOpenAdEventDelegate | MediationAppOpenAdEventDelegate |
GADMediationBannerAd | MediationBannerAd |
GADMediationBannerAdConfiguration | MediationBannerAdConfiguration |
GADMediationBannerAdEventDelegate | MediationBannerAdEventDelegate |
GADMediationCredentials | MediationCredentials |
GADMediationInterstitialAd | MediationInterstitialAd |
GADMediationInterstitialAdConfiguration | MediationInterstitialAdConfiguration |
GADMediationInterstitialAdEventDelegate | MediationInterstitialAdEventDelegate |
GADMediationNativeAd | MediationNativeAd |
GADMediationNativeAdConfiguration | MediationNativeAdConfiguration |
GADMediationNativeAdEventDelegate | MediationNativeAdEventDelegate |
GADMediationRewardedAd | MediationRewardedAd |
GADMediationRewardedAdConfiguration | MediationRewardedAdConfiguration |
GADMediationRewardedAdEventDelegate | MediationRewardedAdEventDelegate |
GADMediationServerConfiguration | MediationServerConfiguration |
| مناقصه در زمان واقعی | |
GADRTBAdapter | RTBAdapter |
GADRTBMediationSignalsConfiguration | RTBMediationSignalsConfiguration |
GADRTBRequestParameters | RTBRequestParameters |
ثابتها
| نسخه ۱۱ | نسخه ۱۲ |
|---|---|
GADAdLoaderAdType.gamBanner | AdLoaderAdType.adManagerBanner |
GADAdSizeBanner | AdSizeBanner |
GADAdSizeFluid | AdSizeFluid |
GADAdSizeFullBanner | AdSizeFullBanner |
GADAdSizeInvalid | AdSizeInvalid |
GADAdSizeLargeBanner | AdSizeLargeBanner |
GADAdSizeLeaderboard | AdSizeLeaderboard |
GADAdSizeMediumRectangle | AdSizeMediumRectangle |
GADAdSizeSkyscraper | AdSizeSkyscraper |
GoogleMobileAdsVersionString | GoogleMobileAdsVersion |
خواص
| نوع | نسخه ۱۱ | نسخه ۱۲ |
|---|---|---|
| GADLoader | loading | isLoading |
| مدیر صوتی و تصویری GAD | audioSessionApplicationManaged | isAudioSessionApplicationManaged |
| نمای بنر GAD | autoloadEnabled | isAutoloadEnabled |
| تبلیغات موبایل GAD | sharedInstance | shared |
applicationMuted | isApplicationMuted | |
| دلیل GADMuteThisAdReason | reasonDescription | reason |
| GADNativeAd | customMuteThisAdAvailable | isCustomMuteThisAdAvailable |
| گزینههای ژست کلیک و تبلیغات سفارشی GADNative | tapsAllowed | areTapsAllowed |
| گزینههای GADNativeAdImageAdLoader | imageLoadingDisabled | isImageLoadingDisabled |
| GADNativeMuteThisAdLoaderOptions | customMuteThisAdRequested | isCustomMuteThisAdRequested |
| درخواست سیگنال بومی GAD | imageLoadingDisabled | isImageLoadingDisabled |
customMuteThisAdRequested | isCustomMuteThisAdRequested | |
| درخواست GAD | neighboringContentURLStrings | neighboringContentURLs |
| اطلاعات پاسخ GAD | extrasDictionary | extras |
| گزینههای تأیید سمت سرور GAD | customRewardString | customRewardText |
| GADSignal | signalString | signal |
| درخواست سیگنال GADSignal | neighboringContentURLStrings | neighboringContentURLs |
| کنترلکنندهی ویدئوی GAD | customControlsRequested | areCustomControlsRequested |
clickToExpandEnabled | isClickToExpandEnabled | |
| گزینههای GADVideo | startMuted | shouldStartMuted |
customControlsRequested | areCustomControlsRequested | |
clickToExpandRequested | isClickToExpandRequested |
توابع
| نوع | نسخه ۱۱ | نسخه ۱۲ |
|---|---|---|
| اندازه GAD | GADPortraitInlineAdaptiveBannerAdSizeWithWidth(_:) | portraitInlineAdaptiveBanner(width:) |
GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(_:) | landscapeInlineAdaptiveBanner(width:) | |
GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(_:) | currentOrientationInlineAdaptiveBanner(width:) | |
GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(_:, _:) | inlineAdaptiveBanner(width:maxHeight:) | |
GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(_:) | portraitAnchoredAdaptiveBanner(width:) | |
GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(_:) | landscapeAnchoredAdaptiveBanner(width:) | |
GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(_:) | currentOrientationAnchoredAdaptiveBanner(width:) | |
GADAdSizeFromCGSize(_:) | adSizeFor(cgSize:) | |
GADAdSizeFullWidthPortraitWithHeight(_:) | fullWidthPortrait(height:) | |
GADAdSizeFullWidthLandscapeWithHeight(_:) | fullWidthLandscape(height:) | |
GADAdSizeEqualToSize(_:, _:) | isAdSizeEqualToSize(size1:size2:) | |
IsGADAdSizeValid(_:) | isAdSizeValid(size:) | |
GADAdSizeIsFluid(_:) | isAdSizeFluid(size:) | |
CGSizeFromGADAdSize(_:) | cgSize(for:) | |
NSStringFromGADAdSize(_:) | string(for:) | |
NSValueFromGADAdSize(_:) | nsValue(for:) | |
GADAdSizeFromNSValue(_:) | adSizeFor(nsValue:) | |
GADClosestValidSizeForAdSizes(_:_:) | closestValidSizeForAdSizes(original:possibleAdSizes:) | |
| نماینده رویداد GADApp | adView(_:didReceiveAppEvent:withInfo:) | adView(_:didReceiveAppEvent:with:) |
interstitialAd(_:didReceiveAppEvent:withInfo:) | adView(_:didReceiveAppEvent:with:) | |
| GADAppOpenAd | load(withAdResponseString:) | load(with:) |
load(withAdUnitID:request:completionHandler:) | load(with:request:completionHandler:) | |
canPresent(fromRootViewController:) | canPresent(from:) | |
present(fromRootViewController:) | present(from:) | |
| نمای بنر GAD | load(withAdResponseString:) | load(with:) |
| GADبینابینی | load(withAdResponseString:) | load(with:) |
load(withAdUnitID:request:completionHandler:) | load(with:request:completionHandler:) | |
canPresent(fromRootViewController:) | canPresent(from:) | |
present(fromRootViewController:) | present(from:) | |
| GADRewardedAd | load(withAdResponseString:) | load(with:) |
load(withAdUnitID:request:completionHandler:) | load(with:request:completionHandler:) | |
canPresent(fromRootViewController:) | canPresent(from:) | |
present(fromRootViewController:userDidEarnRewardHandler:) | present(from:userDidEarnRewardHandler:) | |
| GADRewardedInterstitialAd | load(withAdResponseString:) | load(with:) |
load(withAdUnitID:request:completionHandler:) | load(with:request:completionHandler:) | |
canPresent(fromRootViewController:) | canPresent(from:) | |
present(fromRootViewController:userDidEarnRewardHandler:) | present(from:userDidEarnRewardHandler:) | |
| شماره نسخه GAD | GADGetStringFromVersionNumber(_ version: GADVersionNumber) | string(for:) |
| میانجیگری | ||
| آداپتور شبکه GADMAd | getBannerWith(_:) | getBanner(with:) |
presentInterstitial(fromRootViewController:) | presentInterstitial(from:) | |
getNativeAd(withAdTypes:options:) | getNativeAd(with:options:) | |
| GADMediatedUnifiedNativeAd | didRecordClickOnAsset(withName:view:viewController:) | didRecordClickOnAsset(with:view:viewController:) |
| آداپتور GADMedia | setUpWith(_:completionHandler:) | setUp(with:completionHandler:) |
| GADMediationAdSize | present(fromRootViewController:) | present(from:) |
| GADMediationAppOpenAd | present(fromRootViewController:) | present(from:) |
| GADmediationتبلیغات بینابینی | present(fromRootViewController:) | present(from:) |
| GADmediationRewardedAd | present(fromRootViewController:) | present(from:) |
| GAMInterstitialAd | load(withAdManagerAdUnitID:request:completionHandler:) | load(with:request:completionHandler:) |
تنظیم پارامترهای هدفگیری سفارشی
برای تنظیم هدفگذاری سفارشی روی یک درخواست تبلیغ، از customTargeting استفاده کنید.
تغییرات API برای کنترل وضعیت بیصدا کردن ویدیو
ویژگی isMuted و متد setMute: در GADVideoController با یک ویژگی muted جایگزین شدهاند.
تغییرات در تبلیغات تطبیقی درونخطی
برای بهینهسازی استفاده از فضا، تبلیغات تطبیقی درونخطی در ابتدا هیچ فضایی را در قاب اشغال نمیکنند. فراخوانی CGSizeFromGADAdSize(_:) با اندازه تبلیغ تطبیقی درونخطی، اکنون ارتفاع 0 را برمیگرداند تا زمانی که SDK تبلیغات موبایلی گوگل، تبلیغ را برگرداند.
تبلیغات جستجوی سفارشی حذف شد
کلاسهای زیر بدون جایگزینی حذف میشوند:
-
GADDynamicHeightSearchBannerView -
GADDynamicHeightSearchRequest -
GADSearchBannerView
تغییرات در کدهای خطا
کدهای خطای زیر تغییر یافتهاند:
| کلاس | یادداشتها |
|---|---|
GADErrorMediationNoFill | خطاها اکنون به صورت GADErrorNoFill برمیگردند. |
GADErrorReceivedInvalidResponse | با GADErrorReceivedInvalidAdString جایگزین شده است. |
GADsimulatorID حذف شد
GADSimulatorID حذف شد. شبیهسازها بهطور پیشفرض در حالت آزمایشی هستند.
تغییرات در هدفگذاری سفارشی
دیکشنری customTargeting در GADRequest اکنون به جای String از Any به عنوان نوع مقدار استفاده میکند. این به شما امکان میدهد مقادیر عددی را به API ارسال کنید.
تغییرات در پارامترهای اضافی
- ارسال کلیدها به
additionalParametersدیگر هدفگذاری سفارشی را برای درخواستهای تبلیغ Ad Manager اعمال نمیکند. برای اعمال هدفگذاری سفارشی، به هدفگذاری سفارشی مراجعه کنید.
- ارسال کلید
max_ad_content_ratingبهadditionalParametersدیگر پشتیبانی نمیشود. برای تنظیم حداکثر امتیاز محتوای تبلیغ، به فیلتر کردن محتوای تبلیغ مراجعه کنید.
مهاجرت از نسخه ۱۰ به نسخه ۱۱
حداقل هدف استقرار
حداقل هدف استقرار به iOS 12 افزایش یافته است.
حداقل نسخه Xcode
حداقل نسخه Xcode پشتیبانی شده به 15.1 افزایش یافته است.
نمایش تبلیغات در iOS 12 متوقف شد
نسخه ۱۱.۰.۰ کیت توسعه نرمافزاری تبلیغات موبایل گوگل (Google Mobile Ads SDK) تبلیغات را فقط در دستگاههایی که iOS 13 و بالاتر دارند، نمایش میدهد.
وابستگی GoogleAppMeasurement حذف شد
در نسخه ۱۱.۰.۰، وابستگی به GoogleAppMeasurement حذف شده است. این وابستگی که باعث فعال شدن گزینه معیارهای کاربر در AdMob میشد، در اوایل سال ۲۰۲۴ متوقف خواهد شد. برای ادامه جمعآوری معیارهای کاربر در AdMob، برنامه AdMob خود را به Firebase متصل کنید و Google Analytics for Firebase SDK را در برنامه خود ادغام کنید.
تغییرات در نمایش تبلیغات تمام صفحه
تغییرات زیر بر قالبهای مختلف تبلیغات تأثیر میگذارند:
- برنامه باز است
- بینابینی
- پاداش داده شده
- تبلیغات بینابینی پاداشدار
پارامتر view controller در -canPresentFromRootViewController:error: و -presentFromRootViewController: قابل تهی شدن است. اگر nil ارسال شود، تبلیغ از بالاترین view controller در سلسله مراتب view controller نمایش داده میشود.
روشهای حذفشده
روشهای زیر حذف میشوند.
| نوع نسخه ۱۱.۰.۰ | روش | یادداشتها |
|---|---|---|
| GADAppOpenAd | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) | به جای آن از load(withAdUnitID adUnitID: String, request: GADRequest?) استفاده کنید. |
| GADMediationBannerAdEvent Delegate | willBackgroundApplication() | بدون جایگزینی. |
| واسطهگری GADمیانجیگری تبلیغات رویدادنماینده | willBackgroundApplication() | بدون جایگزینی. |
| نماینده رویداد تبلیغات بومی GAD | willBackgroundApplication() | بدون جایگزینی. |
| نماینده رویداد پاداش داده شده (GADMediationRewardedAdEventDelegate) | didRewardUser(with reward: GADAdReward) | به جای آن از didRewardUser() استفاده کنید. |
| منبع اعلان تبلیغات بومی یکپارچه GADMediatedUnified | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) | بدون جایگزینی. |
| پیکربندی GADRequest | setSameAppKeyEnabled(_ enabled: Bool) | به جای آن از setPublisherFirstPartyIDEnabled(_ enabled: Bool) استفاده کنید. |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) | به جای آن از ویژگی tagForUnderAgeOfConsent استفاده کنید. | |
tag(forChildDirectedTreatment childDirectedTreatment: Bool) | به جای آن از ویژگی tagForChildDirectedTreatment استفاده کنید. |
خواص حذف شده
ویژگیهای زیر حذف میشوند.
| کلاس v11.0.0 | ملک | یادداشتها |
|---|---|---|
| پیکربندی GADMediationAd | موقعیت مکانی hasUser | بدون جایگزینی. |
| کاربرLatitude | ||
| طول جغرافیایی کاربر | ||
| کاربر موقعیت مکانی دقت در مترها | ||
| درمان کودک محور | به جای آن از GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment استفاده کنید. | |
| اطلاعات پاسخ GAD | نام کلاس شبکه ad | به جای آن از adNetworkClassName از loadedAdNetworkResponseInfo استفاده کنید. |
حذف شد GADFormatناشناخته
GADAdFormatUnknown بدون جایگزینی حذف شد.
تغییرات در ثبت نسخه SDK
نسخه ۱۱.۰.۰، sdkVersion حذف میکند. برای ثبت نسخه SDK تبلیغات موبایلی گوگل، به جای آن از versionNumber استفاده کنید.
نسخه ۱۰.۰.۰
GADMobileAds.sharedInstance().sdkVersion
نسخه ۱۱.۰.۰
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
تغییرات در مدیریت خطای GADAdLoader
از نسخه ۱۱.۰.۰ به بعد، اگر delegate GADAdLoader با پروتکل نماینده انواع تبلیغات درخواستی مطابقت نداشته باشد، درخواست تبلیغ ارسال نمیکند. پیش از این، پس از ارسال درخواست تبلیغ، با شکست مواجه میشد.
تغییرات در رفتار آزمایش
جدولی را ببینید که شرایط بهروز شده برای زمانی که ویژگیهای زیر مقدار true برمیگردانند را نشان میدهد.
| کلاس | ملک |
|---|---|
| پیکربندی GADMediationAd | isTestRequest |
| درخواست رویداد سفارشی GAD | isTesting |
| نسخه ۱۰.۰.۰ | نسخه ۱۱.۰.۰ |
|
|
مهاجرت از نسخه ۹ به نسخه ۱۰
نمایش تبلیغات در iOS 11 متوقف شد
نسخه ۱۰.۰.۰ کیت توسعه نرمافزاری تبلیغات موبایل گوگل (Google Mobile Ads SDK) تبلیغات را فقط در دستگاههایی که iOS 12 و بالاتر دارند، نمایش میدهد.
ارتقا به نسخه ۱۰.۰.۰ کیت توسعه نرمافزاری تبلیغات موبایل گوگل (Google Mobile Ads SDK) برنامه شما را در دستگاههای iOS 11 و iOS 10 دچار مشکل نمیکند، با این حال، هیچ تبلیغی در آن دستگاهها نمایش داده نخواهد شد.
الزامات شناسه برنامه مدیر تبلیغات
شناسه برنامه مدیریت تبلیغات (Ad Manager App ID) اکنون در Info.plist برای همه برنامههای مدیریت تبلیغات (Ad Manager) الزامی است و به فرمت ca-app-pub-################~########## نیاز دارد. برای جزئیات بیشتر به بهروزرسانی Info.plist خود مراجعه کنید.
الزامات GoogleAppMeasurement.xcframework
GoogleAppMeasurement.xcframework اکنون برای همه برنامههای مدیریت تبلیغات مورد نیاز است. اگر SDK تبلیغات موبایلی گوگل را از طریق Cocoapods یا Swift Package Manager نصب کنید، هیچ اقدام اضافی لازم نیست. اگر چارچوبها را به صورت دستی نصب میکنید، برای جزئیات بیشتر به دانلود دستی مراجعه کنید.
ساخت و ساز با بیتکد دیگر پشتیبانی نمیشود
اکنون غیرفعال کردن بیتکد در برنامههای تلفن همراه شما برای ادغام SDK تبلیغات موبایلی گوگل الزامی است.
انواع حذف شده
| نوع | یادداشتها |
|---|---|
| جنسیت GAD | بدون جایگزینی. |
| پروتکل آداپتور شبکه تبلیغات ویدیویی مبتنی بر پاداش GADM | تمام آداپتورهای میانجیگری پاداشدار که در Choose Networks فهرست شدهاند، بیش از یک سال است که استفاده از این پروتکلها را متوقف کردهاند. برای میانجیگری و رویدادهای سفارشی از GADMediationAdapter استفاده کنید. |
| پروتکل اتصالدهنده شبکه تبلیغات ویدیویی مبتنی بر پاداش GADM |
خواص حذف شده
ویژگیهای زیر بدون جایگزینی حذف میشوند.
| کلاس v10.0.0 | ملک |
|---|---|
| درخواست میانجیگری GAD | کاربرتاریخ تولد |
| کاربرجنسیت | |
| کاربر موقعیت مکانی دارد | |
| کاربرLatitude | |
| طول جغرافیایی کاربر | |
| کاربر موقعیت مکانی دقت در مترها | |
| کاربرموقعیتتوضیحات | |
| درخواست رویداد سفارشی GAD | کاربر موقعیت مکانی دارد |
| کاربرLatitude | |
| طول جغرافیایی کاربر | |
| کاربر موقعیت مکانی دقت در مترها | |
| کاربرموقعیتتوضیحات |
مهاجرت از نسخه ۸ به نسخه ۹
نمایش تبلیغات در iOS 10 متوقف شد
حداقل نسخه iOS که SDK تبلیغات موبایلی گوگل نسخه ۹.۰.۰ از آن پشتیبانی میکند، iOS 11 است.
ارتقا به نسخه ۹.۰.۰ کیت توسعه نرمافزاری تبلیغات موبایل گوگل (Google Mobile Ads SDK) برنامه شما را در دستگاههای iOS 10 دچار مشکل نمیکند، با این حال، هیچ تبلیغی در آن دستگاهها نمایش داده نخواهد شد.
اعمال سختگیرانهتر کنترلهای نوار وضعیت
از نسخه ۹.۰.۰ به بعد، وقتی تبلیغات تمام صفحه نمایش داده میشوند، برنامه شما باید مطمئن شود که تبلیغات میتوانند نمایش نوار وضعیت را کنترل کنند. در صورت عدم انجام این کار، پیام خطایی در گزارشها مشاهده خواهید کرد.
بسته به طرحبندی خاص view controllerها در برنامه شما، ممکن است نیازی به ایجاد هیچ تغییری برای اطمینان از این موضوع نداشته باشید. در نظر بگیرید که آیا نیاز به تنظیم ویژگی childViewControllerForStatusBarHidden در rootViewController مربوط به تبلیغ خود دارید یا خیر.
تغییر نام adDidPresentFullScreenContent: به adWillPresentFullScreenContent:
هیچ تغییر رفتاری ایجاد نشده است. متد delegate درست قبل از نمایش تبلیغ فراخوانی میشود، بنابراین نام جدید متد، عملکرد آن را بهتر نشان میدهد.
حذف API تنظیمات مکان در GADRequest
- (void)setLocationWithLatitude:longitude:accuracy: از GADRequest حذف شده است زیرا دادههای موقعیت مکانی توسط گوگل برای هدفگیری تبلیغات استفاده نمیشود. در صورت لزوم، از APIهای شخص ثالث برای ارائه اطلاعات به شبکههای تبلیغاتی شخص ثالث استفاده کنید.
منسوخ شدن رابطهای رویداد سفارشی
رویدادهای سفارشی به ناشرانی که از Ad Manager Mediation استفاده میکنند، این امکان را میدهد که برای شبکه تبلیغاتی که جزو شبکههای تبلیغاتی پشتیبانیشده نیست، میانجیگری آبشاری اضافه کنند.
تمام پروتکلهای رویداد سفارشی منسوخ شدهاند. در عوض، از پروتکلهای موجود GADMediationAdapter و GADMediationAdEventDelegate برای دستیابی به همان عملکردها استفاده کنید. این تغییر وضوح را بهبود میبخشد و شما را قادر میسازد رویدادهای سفارشی برای تبلیغات جایزهدار و تبلیغات بین اسکرولی ایجاد کنید که قبلاً در دسترس نبودند.
رابطهای برنامهنویسی کاربردی (API)
جدول زیر APIهای آداپتور میانجیگری مربوط به APIهای رویدادهای سفارشی را که باید از نسخه 9.0.0 به بعد استفاده شوند، فهرست میکند.
| نسخه ۸ | نسخه ۹ | |
|---|---|---|
| بنر رویداد سفارشی GAD GADCustomEventبینابینی GADCustomEventNativeAd | آداپتور GADMedia | بنر تبلیغاتی GADMediation GADmediationتبلیغات بینابینی GADmediationInterscrollerAd GADmediationRewardedAd GADmediationNativeAd |
delegate | نماینده (Delegate) توسط کنترلکنندهی تکمیل بارگذاری هر تابع بارگذاری از کلاس GADMediationAdapter بازگردانده میشود. | |
-init | -init | |
-requestBannerAd:parameter: label:request: | -loadBannerForAdConfiguration: completionHandler: | |
-requestInterstitialAdWith Parameter:label:request: | -loadInterstitialFor AdConfiguration: completionHandler: | |
-requestNativeAdWithParameter: request:adTypes:options: rootViewController: | -loadNativeAdFor AdConfiguration: completionHandler: | |
| ناموجود | -loadInterscrollerAdFor AdConfiguration: completionHandler: | |
| ناموجود | -loadRewardedAdFor AdConfiguration: completionHandler: | |
-presentFromRootViewController: | -presentFromViewController: | |
-handlesUserClicks | -handlesUserClicks | |
-handlesUserImpressions | -handlesUserImpressions | |
روشهای نماینده
جدول زیر روشهای مربوط به نماینده رویداد تبلیغات میانجیگری و روشهای نماینده رویداد سفارشی را که باید از نسخه ۹.۰.۰ به بعد استفاده شوند، فهرست میکند.
| نسخه ۸ | نسخه ۹ | |
|---|---|---|
| نماینده بنر رویداد GADCustomEventBannerDelegate نماینده بینابینی GADCustomEvent GADCustomEventNativeAdDelegate | نماینده رویداد GADMediationAdEvent | GADmediationAd |
-customEventBanner:didReceiveAd:-customEventInterstitialDidReceiveAd: | وضعیت بارگذاری تبلیغ در کنترلکنندهی تکمیل بارگذاری هر تابع بارگذاری در کلاس GADMediationAdapter گنجانده شده است. | |
-customEventBanner:didFailAd:-customEventInterstitial:didFailAd: | ||
-customEventBannerWasClicked:-customEventInterstitialWasClicked: | -reportClick | |
-customEventBannerWill PresentModal:-customEventInterstitialWill PresentModal: | -willPresentFullScreenView | |
-customEventBannerWill DismissModal:-customEventInterstitialWill DismissModal: | -willDismissFullScreenView | |
-customEventBannerDid DismissModal:-customEventInterstitialDid DismissModal: | -didDismissFullScreenView | |
-customEventBannerWill LeaveApplication:-customEventInterstitialWill LeaveApplication: | -willBackgroundApplication | |
viewControllerFor PresentingModalView | -[GADMediationBannerAd view] | |
سایر متدها و ثابتهای حذف/جایگزینشده
| تغییرات در متد، ثابت یا ویژگی | |
|---|---|
ثابتهای پیشوندی kGAD- | حذف شد. از ثابتهای پیشوندی GAD- استفاده کنید. |
GADAdNetworkResponseInfo | credentials حذف شدند. به جای آن از adUnitMapping استفاده کنید. |
GAMRequest | kGAMSimulatorID در GAMRequest منسوخ شده است. به جای آن از GADSimulatorID در GADRequestConfiguration استفاده کنید. |
GADCustomNativeAd | mediaView در GADCustomNativeAd منسوخ شده است. به جای آن از mediaContent استفاده کنید. |
APIهای خرید درونبرنامهای در GoogleMobileAds | رابطهای برنامهنویسی کاربردی (API) inAppPurchase در GoogleMobileAds حذف شدند. |
مهاجرت از نسخه ۷ به نسخه ۸
نسخه ۸.۰.۰ کیت توسعه نرمافزاری تبلیغات موبایلی گوگل (Google Mobile Ads SDK) چند تغییر عمده و همچنین برخی تغییر نامها و حذف APIها را معرفی میکند.
بهروزرسانیهای API با فرمت تمام صفحه
از نسخه ۸.۰.۰ به بعد، تبلیغات بینابینی و جایزهدار برای هماهنگی بیشتر، از یک سبک تبلیغاتی تمامصفحه عمومی استفاده میکنند. این APIهای تبلیغاتی تمامصفحه جدید، دو تفاوت عمده با APIهای تبلیغاتی تمامصفحه نسخه ۷ دارند:
loadمتد کلاس استاتیک.رویکرد قبلی برای بارگذاری/نمایش یک تبلیغ تمام صفحه به شرح زیر است:
- یک نمونه شیء تبلیغ ایجاد کنید و یک ارجاع به آن داشته باشید.
- یک نماینده (delegate) اختصاص دهید که بارگذاری و نمایش فراخوانیهای برگشتی (callbacks) را مدیریت کند.
- یک تبلیغ بارگذاری کنید.
- با استفاده از
isReadyبررسی کنید که آیا تبلیغ بارگذاری شده است یا خیر. - تبلیغ را نشان دهید.
در نسخه ۸، این رویکرد کمی تغییر کرده است. فراخوانیهای Load دیگر بخشی از یک delegate نیستند. در عوض، آنها به عنوان یک completion handler به متد
loadارسال میشوند:- یک متد بارگذاری استاتیک را روی کلاس ad فراخوانی کنید و یک کنترلکنندهی تکمیل بارگذاری ارائه دهید.
- در فراخوانی تکمیل بارگذاری، به تبلیغ بارگذاری شدهای که برگردانده شده است، ارجاع دهید.
- یک نماینده (delegate) اختصاص دهید که فراخوانیهای بازگشتی show را مدیریت کند.
- تبلیغ را نشان دهید.
رویکرد جدید این مزایا را ارائه میدهد:
- شما هرگز به تبلیغی که بارگذاری نشده باشد، ارجاع نخواهید داد.
- لازم نیست هنگام بارگذاری یک شیء تبلیغاتی، آن را نگه دارید.
رویدادهای تبلیغاتی مداوم.
نوع رویداد API موجود رابط برنامهنویسی کاربردی نسخه ۸ بارگذاری رویدادها GADInterstitialDelegateیاGADRewardedAdDelegateGAMInterstitialAdLoadCompletionHandlerیاGADRewardedAdLoadCompletionHandlerرویدادهای ارائه GADFullScreenContentDelegateپیش از این، برای گوش دادن به هرگونه رویداد تبلیغاتی، شما یک کلاس که پروتکل
GADInterstitialDelegateرا در ویژگی delegate یک تبلیغ بینابینی پیادهسازی میکرد، یا یک کلاس که پروتکلGADRewardedAdDelegateرا در ویژگی delegate یک تبلیغ پاداشی پیادهسازی میکرد، بسته به اینکه از چه فرمتی استفاده میکنید، ثبت میکردید. همین delegate متدهایی مربوط به چرخه حیات بارگذاری و ارائه یک تبلیغ داشت.در نسخه ۸، رویدادهای بارگذاری و ارائه از هم جدا هستند. اکنون میتوانید هر زمان قبل از نمایش یک تبلیغ، یک
GADFullScreenContentDelegateثبت کنید، به جای اینکه لازم باشد قبل از بارگذاری تبلیغ، یک delegate واحد تنظیم کنید. رویدادهای بارگذاری تبلیغ، که مختص هر قالب هستند، به یک کنترلکننده تکمیل بارگذاری واحد که در متد load ارسال میشود، منتقل میشوند.
بینابینی
بارگذاری آگهی
قطعه کدهای زیر به شما نشان میدهند که چگونه یک تبلیغ بینابینی را بارگذاری کنید و به رویدادهایی که هنگام بارگذاری موفق یا ناموفق تبلیغ رخ میدهند، گوش دهید.
نسخه ۷
سویفت
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: DFPInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial") interstitial.delegate = self let request = GAMRequest() interstitial.load(request) } /// Tells the delegate an ad request succeeded. func interstitialDidReceiveAd(_ ad: DFPInterstitial) { print("Interstitial ad loaded.") } /// Tells the delegate an ad request failed. func interstitial(_ ad: DFPInterstitial, didFailToReceiveAdWithError error: GADRequestError) { print("Interstitial ad failed to load with error: \(error.localizedDescription)") } }
هدف-سی
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) DFPInterstitial *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:@"/21775744923/example/interstitial"]; self.interstitial.delegate = self; GAMRequest *request = [GAMRequest request]; [self.interstitial loadRequest:request]; } /// Tells the delegate an ad request succeeded. - (void)interstitialDidReceiveAd:(DFPInterstitial *)ad { NSLog(@"Insterstitial ad loaded."); } /// Tells the delegate an ad request failed. - (void)interstitial:(DFPInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error { NSLog(@"Interstitial ad failed to load with error: %@", [error localizedDescription]); }
نسخه ۸
سویفت
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADFullScreenContentDelegate { var interstitial: GAMInterstitialAd? override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GAMInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738", request: request, completionHandler: { (ad, error) in if let error = error { print("Failed to load interstitial ad with error: \(error.localizedDescription)") return } self.interstitial = ad self.interstitial.fullScreenContentDelegate = self } ) } }
هدف-سی
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GAMInterstitialAd *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial" request:request completionHandler:^(GAMInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]); return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; }
نمایش آگهی
نسخه ۷
سویفت
func showInterstitial() { ... if interstitial.isReady { interstitial.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
هدف-سی
- (void)showInterstitial: { ... if (self.interstitial.isReady) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
نسخه ۸
سویفت
func showInterstitial() { ... if let ad = interstitial { ad.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
هدف-سی
- (void)showInterstitial: { ... if (self.interstitial) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
رویدادهای تبلیغاتی ارائه
قطعه کدهای زیر به شما نشان میدهند که چگونه فراخوانیهای برگشتی را در زمان نمایش تبلیغ (موفق یا ناموفق) و زمان رد شدن آن مدیریت کنید.
نسخه ۷
سویفت
override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial") interstitial.delegate = self ... } /// Tells the delegate that an interstitial will be presented. func interstitialWillPresentScreen(_ ad: DFPInterstitial) { print("Interstitial ad will be presented.") } /// Tells the delegate the interstitial is to be animated off the screen. func interstitialWillDismissScreen(_ ad: DFPInterstitial) { print("Interstitial ad will be dismissed.") } /// Tells the delegate the interstitial had been animated off the screen. func interstitialDidDismissScreen(_ ad: DFPInterstitial) { print("Interstitial ad dismissed.") } /// Tells the delegate that a user click will open another app /// (such as the App Store), backgrounding the current app. /// /// This is not a reliable callback for an ad click event and is removed in /// version 8. If you wish to listen to an ad causing a user to leave the app, /// use applicationWillResignActive: or sceneWillResignActive: instead. func interstitialWillLeaveApplication(_ ad: DFPInterstitial) { print("Interstitial ad will leave application.") }
هدف-سی
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:"/21775744923/example/interstitial"]; self.interstitial.delegate = self; ... } /// Tells the delegate that an interstitial will be presented. - (void)interstitialWillPresentScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will be presented."); } /// Tells the delegate the interstitial is to be animated off the screen. - (void)interstitialWillDismissScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will be dismissed."); } /// Tells the delegate the interstitial had been animated off the screen. - (void)interstitialDidDismissScreen:(DFPInterstitial *)ad { NSLog(@"Interstitial ad dismissed."); } /// Tells the delegate that a user click will open another app /// (such as the App Store), backgrounding the current app. /// /// This is not a reliable callback for an ad click event and is removed in /// version 8. If you wish to listen to an ad causing a user to leave the app, /// use applicationWillResignActive: or sceneWillResignActive: instead. - (void)interstitialWillLeaveApplication:(DFPInterstitial *)ad { NSLog(@"Interstitial ad will leave application."); }
نسخه ۸
سویفت
override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GAMInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738", request: request, completionHandler: { (ad, error) in if let error = error { print(error.localizedDescription) return } self.interstitial = ad self.interstitial.fullScreenContentDelegate = self } ) } func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Ad did present full screen content.") } func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) { print("Ad failed to present full screen content with error \(error.localizedDescription).") } func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Ad did dismiss full screen content.") }
هدف-سی
- (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial" request:request completionHandler:^(GAMInterstitialAd *ad, NSError *error) { if (error) { NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]) return; } self.interstitial = ad; self.interstitial.fullScreenContentDelegate = self; }]; } - (void)adDidPresentFullScreenContent:(id)ad { NSLog(@"Ad did present full screen content."); } - (void)ad:(id )ad didFailToPresentFullScreenContentWithError:(NSError *)error { NSLog(@"Ad failed to present full screen content with error %@.", [error localizedDescription]); } - (void)adDidDismissFullScreenContent:(id )ad { NSLog(@"Ad did dismiss full screen content."); }
پاداش داده شده
بارگذاری آگهی
نسخه ۷
سویفت
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADRewardedAdDelegate { /// The rewarded ad. var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd.delegate = self rewardedAd?.load(GAMRequest()) { error in if let error = error { print("Rewarded ad failed to load with error: \(error.localizedDescription)") } else { print("Rewarded ad loaded.") } } } }
هدف-سی
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.rewardedAd = [[GADRewardedAd alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"]; self.rewardedAd.delegate = self; GAMRequest *request = [GAMRequest request]; [self.rewardedAd loadRequest:request completionHandler:^(GADRequestError * _Nullable error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); } else { NSLog(@"Rewarded ad loaded."); } }]; }
نسخه ۸
سویفت
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADFullScreenContentDelegate { /// The rewarded ad. var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136", request: request, completionHandler: { (ad, error) in if let error = error { print("Rewarded ad failed to load with error: \(error.localizedDescription)") return } self.rewardedAd = ad self.rewardedAd?.fullScreenContentDelegate = self } ) } }
هدف-سی
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GADRewardedAd *rewardedAd; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; NSLog(@"Rewarded ad loaded."); self.rewardedAd.fullScreenContentDelegate = self; }
نمایش تبلیغ و مدیریت پاداش
تبلیغات پاداشی شما را ملزم میکنند که رویدادی را که کاربر پاداشی کسب میکند، مدیریت کنید. در نسخه ۷ از API GADRewardedAd ، شما rewardedAd:userDidEarnReward: به عنوان بخشی از پروتکل GADRewardedAdDelegate پیادهسازی میکنید. برای نسخه ۸، شما GADUserDidEarnRewardHandler را برای نمایش تبلیغ پیادهسازی میکنید.
نسخه ۷
سویفت
func showRewardedAd() { ... if rewardedAd.isReady { rewardedAd.present(fromRootViewController: self delegate:self) } else { print("Ad wasn't ready") } } /// Tells the delegate that the user earned a reward. func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarnReward: GADAdReward) { // TODO: Reward the user. }
هدف-سی
- (void)showRewardedAd: { ... if (self.rewardedAd.isReady) { [self.rewardedAd presentFromRootViewController:self delegate:self]; } else { NSLog(@"Ad wasn't ready"); } } /// Tells the delegate that the user earned a reward. - (void)rewardedAd:(GADRewardedAd *)rewardedAd userDidEarnReward:(GADAdReward *)reward { // TODO: Reward the user. }
نسخه ۸
سویفت
func showRewardedAd() { ... if let ad = rewardedAd { ad.present(fromRootViewController: self, userDidEarnRewardHandler: { let reward = ad.adReward // TODO: Reward the user. } ) } else { print("Ad wasn't ready") } }
هدف-سی
- (void)showRewardedAd: { ... if (self.rewardedAd) { [self.rewardedAd presentFromRootViewController:self userDidEarnRewardHandler:^ { GADAdReward *reward = self.rewardedAd.adReward; // TODO: Reward the user. }]; } else { NSLog(@"Ad wasn't ready"); } }
رویدادهای تبلیغاتی ارائه
با API GADRewardedAd شما یک GADRewardedAdDelegate به متدی که تبلیغ را نمایش میدهد، ارسال میکنید. با API GADRewardedAd ، شما یک GADFullscreenContentDelegate را به عنوان یک ویژگی روی تبلیغ، قبل از نمایش آن، تنظیم میکنید.
نسخه ۷
سویفت
func showRewardedAd() { ... if rewardedAd.isReady { rewardedAd.present(fromRootViewController: self delegate:self) } else { print("Ad wasn't ready") } } /// Tells the delegate that the rewarded ad was presented. func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) { print("Rewarded ad failed to present with error: \(error.localizedDescription).") }
هدف-سی
- (void)showRewardedAd: { ... if (self.rewardedAd.isReady) { [self.rewardedAd presentFromRootViewController:self delegate:self]; } else { NSLog(@"Ad wasn't ready"); } } /// Tells the delegate that the rewarded ad was presented. - (void)rewardedAdDidPresent:(GADRewardedAd *)rewardedAd { NSLog(@"Rewarded ad presented."); } /// Tells the delegate that the rewarded ad failed to present. - (void)rewardedAd:(GADRewardedAd *)rewardedAd didFailToPresentWithError:(NSError *)error { NSLog(@"Rewarded ad failed to present with error: %@", [error localizedDescription]); } /// Tells the delegate that the rewarded ad was dismissed. - (void)rewardedAdDidDismiss:(GADRewardedAd *)rewardedAd { NSLog(@"Rewarded ad dismissed."); }
نسخه ۸
سویفت
override func viewDidLoad() { super.viewDidLoad() let request = GAMRequest() GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136", request: request, completionHandler: { (ad, error) in if let error = error { print(error.localizedDescription) return } self.rewardedAd = ad self.rewardedAd?.fullScreenContentDelegate = self } ) } /// Tells the delegate that the rewarded ad was presented. func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) { print("Rewarded ad failed to present with error: \(error.localizedDescription).") }
هدف-سی
- (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313" request:request completionHandler:^(GADRewardedAd *ad, NSError *error) { if (error) { NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]); return; } self.rewardedAd = ad; NSLog(@"Rewarded ad loaded."); self.rewardedAd.fullScreenContentDelegate = self; } /// Tells the delegate that the rewarded ad was presented. - (void)adDidPresentFullScreenContent:(id)ad { NSLog(@"Rewarded ad presented."); } /// Tells the delegate that the rewarded ad failed to present. - (void)ad:(id )ad didFailToPresentFullScreenContentWithError:(NSError *)error { NSLog(@"Rewarded ad failed to present with error: %@", [error localizedDescription]); } /// Tells the delegate that the rewarded ad was dismissed. - (void)adDidDismissFullScreenContent:(id )ad { NSLog(@"Rewarded ad dismissed."); }
حذف API قدیمی GADRewardedBasedVideoAd
رابط برنامهنویسی کاربردی جدیدتر GADRewardedAd اولین بار در مارس ۲۰۱۹ معرفی شد و بیش از ۱۸ ماه است که رابط برنامهنویسی کاربردی پاداشدار ترجیحی بوده است. این رابط در مقایسه با رابط برنامهنویسی کاربردی قدیمی GADRewardedBasedVideoAd پیشرفتهای بیشتری داشته است، از جمله قابلیت بارگذاری بیش از یک تبلیغ پاداشدار در یک زمان.
API قدیمی GADRewardedBasedVideoAd در SDK نسخه ۸.۰.۰ حذف شده است.
منسوخ شدن بنر هوشمند به نفع بنر تطبیقی
بنرهای هوشمند به نفع بنرهای تطبیقی منسوخ شدهاند. بنرهای تطبیقی عملکرد برتر و انعطافپذیری بیشتری در تنظیم عرض تبلیغ ارائه میدهند. اگر ترجیح میدهید به استفاده از بنرهای تمام عرض ادامه دهید، همچنان میتوانید این کار را با استفاده از بنر تطبیقی انجام دهید، همانطور که در قطعه کد زیر نشان داده شده است:
سویفت
class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // Note: The safe area is not known until viewWillAppear. let adSize = getFullWidthAdaptiveAdSize() } func getFullWidthAdaptiveAdSize() -> GADAdSize { // Here safe area is taken into account, hence the view frame is used after the // view has been laid out. let frame = { () -> CGRect in if #available(iOS 11.0, *) { return view.frame.inset(by: view.safeAreaInsets) } else { return view.frame } }() return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width) } }
هدف-سی
@implementation ViewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Note: The safe area is not known until viewWillAppear. GADAdSize adSize = [self getFullWidthAdaptiveAdSize]; } - (GADAdSize)getFullWidthAdaptiveAdSize { CGRect frame = self.view.frame; // Here safe area is taken into account, hence the view frame is used after // the view has been laid out. if (@available(iOS 11.0, *)) { frame = UIEdgeInsetsInsetRect(self.view.frame, self.view.safeAreaInsets); } return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width); } @end
حذف تماس برگشتی برنامه را ترک کنید
تابع فراخوانی willLeaveApplication برای همه فرمتهای تبلیغاتی حذف شده و متدهای applicationDidEnterBackground: و sceneDidEnterBackground: جایگزین آن شدهاند. با استفاده از APIهای سطح سیستم عامل، هر زمان که کاربران برنامه شما را ترک کنند، صرف نظر از اینکه آیا این ترک به دلیل تعامل تبلیغاتی بوده یا خیر، به شما اطلاع داده میشود.
توجه داشته باشید که فراخوانی willLeaveApplication هرگز قرار نبود یک کنترلکننده کلیک روی تبلیغات باشد و تکیه بر این فراخوانی برای گزارش کلیکها، معیار دقیقی ایجاد نمیکرد. برای مثال، کلیک روی آیکون AdChoices که یک مرورگر خارجی را اجرا میکرد، فراخوانی را فراخوانی میکرد اما یک کلیک را شمارش نمیکرد.
تغییر نام کلاسها
جدول زیر نام کلاسهای خاصی را که در نسخه ۸ تغییر یافته یا حذف شدهاند، فهرست میکند. به طور خلاصه:
- تمام کلاسهای مربوط به
GADUnifiedNativeAdبهGADNativeAdتغییر نام دادهاند. -
GADRewardBasedVideoAd،GADNativeExpressAdViewوGADInstreamAdحذف شدهاند. - تمام کلاسهای دارای پیشوند
DFPبا پیشوندGAMجایگزین شدهاند.
| کلاس v7.68.0 | کلاس v8.0.0 |
|---|---|
| نمای بنر DFP | نمای بنر گام |
| گزینههای نمایش بنر DFP | گزینههای نمایش بنر گام |
| DFPبینابینی | GAMInterstitialAd |
| درخواست DFP | درخواست GAM |
| خطای درخواست GAD | NSError |
| GADUnifiedNativeAdView | GADNativeAdView |
| GADUnifiedNativeAd | GADNativeAd |
| شناسههای دارایی تبلیغات بومی GADUnified | شناسههای دارایی تبلیغات بومی GAD |
| نماینده تبلیغات بومی GADUnified | نماینده تبلیغات GADNative |
| GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
| قالب سفارشی GADNativeAd | GADCustomNativeAd |
| GADNativeCustomTemplateAdLoaderDelegate | نماینده GADCustomNativeAdLoaderDelegate |
| نماینده تبلیغات GADNative | نماینده تبلیغات بومی GAD |
| خرید GADInApp | حذف شد |
| GADبینابینی | GADبینابینی |
| GADNativeExpressAdView | حذف شد |
| تبلیغات ویدیویی مبتنی بر پاداش GAD | حذف شد |
| GADInstreamAd | حذف شد |
| GADInstreamAdView | حذف شد |
روشهای حذفشده/جایگزینشده
جدول زیر تغییرات خاص در نسخه ۸ را فهرست میکند. به طور خلاصه:
- متدها و ویژگیهایی که قبلاً منسوخ شده بودند، حذف شدهاند.
-
-willLeaveApplication:متدهای نماینده برای همه قالبها حذف شدهاند. - نام کلاس شبکه تبلیغاتی به ویژگی
GADResponseInfoمنتقل شده است. - شناسه دستگاه آزمایشی به ویژگی
GADRequestConfigurationمنتقل شده است.
| کلاس v7.68.0 | نسخه ۷.۶۸.۰ رابط برنامهنویسی کاربردی | نسخه ۸.۰.۰ رابط برنامهنویسی کاربردی | یادداشتها |
|---|---|---|---|
| تبلیغات موبایل GAD | +configureWithApplicationID: | -startWithCompletionHandler: | شناسه برنامه اکنون در Info.plist تنظیم شده است. |
| +غیرفعال کردن گزارش خرید خودکار درونبرنامهای | -disableAutomatedInApp PurchaseReporting | ||
| +غیرفعال کردن گزارش خرابی SDK | -disableSDKCrashReporting | ||
| درخواست GAD | دستگاههای تست | شناسههای دستگاه تست GADRequestConfiguration | ویژگی testDeviceIdentifiers برای همه درخواستهای تبلیغ اعمال میشود، در حالی که ویژگی قدیمی testDevices برای هر درخواست تنظیم میشد. |
| جنسیت | حذف شد | ||
| تولد | حذف شد | ||
| +نسخه sdk | GADMobileAds.sharedInstance.sdkVersion | ||
| -تنظیم تاریخ تولد با ماه:روز:سال: | حذف شد | ||
| -تنظیم موقعیت مکانی با توضیحات: | -تنظیم موقعیت مکانی با عرض جغرافیایی:طول جغرافیایی:دقت: | ||
| -tagForChildDirectedTreatment: | [برچسب پیکربندی GADMobileAds.sharedInstance.requestForChildDirectedTreatment] | ||
| کد خطای GAD | خطای kGAD* | خطای GAD* | پیشوند k از تمام ثابتهای کد خطا حذف میشود. |
| نمای بنر GAD | دارای بهروزرسانی خودکار است | بارگذاری خودکارفعال | |
| نماینده خرید درونبرنامهای | حذف شد | ||
| واسطه AdView | حذف شد | ||
| نام کلاس شبکه ad | اطلاعات پاسخ.adNetworkClassName | ||
| نمای بنر DFP | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
| گزینههای نمایش بنر DFP | -adSizeDelegate | حذف شد | |
| نماینده GADBannerView | -adViewDidReceiveAd: | بنرنمایشدریافتتبلیغات | |
| -adView:didFailToReceive خطای AdWithError: | -bannerView:didFailToReceiveAdWithError: | ||
| -adViewWillPresentScreen: | -bannerViewWillPresentScreen: | ||
| -adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
| -adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
| -adViewWillLeaveApplication: | حذف شد | ||
| قالب سفارشی GADNativeAd | شناسه الگو | شناسه قالب آگهی سفارشی بومی GAD | |
| -performClickOnAssetWithKey: customClickHandler: | -performClickOnAssetWithKey: | ||
| گزینههای بارگذاری تصویر و تبلیغات GADNativeAd | جهتگیری تصویر ترجیحی | GADNativeAdMediaAdOptions .mediaAspectRatio | |
| GADبینابینی | نماینده خرید درونبرنامهای | حذف شد | |
| آماده است | حذف شد | به جای آن از canPresentFrom RootViewController:error: استفاده کنید. | |
| استفاده شده است | حذف شد | ||
| -آغازین | -initWithAdUnitID: | ||
| -تنظیمAdUnitID: | -initWithAdUnitID: | ||
| نام کلاس شبکه ad | اطلاعات پاسخ.adNetworkClassName | ||
| -interstitialWill LeaveApplication: | حذف شد | ||
| GADUnifiedNativeAd | کنترلکننده ویدیو | کنترلکنندهی محتوای رسانهای.ویدئویی | |
| نام کلاس شبکه ad | اطلاعات پاسخ.adNetworkClassName |