בדף הזה מפורט על ההעברות לגרסה הנוכחית ולגרסה הקודמת.
מעבר מגרסה 10 לגרסה 11
יעד פריסה מינימלי
יעד הפריסה המינימלי הוגדל ל-iOS 12.
גרסת Xcode מינימלית
הגרסה המינימלית הנתמכת של Xcode הוגדלה ל-15.1.
הצגת המודעות נפסקת ב-iOS 12
בגרסה 11.0.0 של Google Mobile Ads SDK אפשר להציג מודעות רק במכשירים עם iOS מגרסה 13 ואילך.
התלות ב-GoogleAppMeasurement הוסרה
בגרסה 11.0.0, התלות ב-GoogleAppMeasurement
הוסרה. התלות הזאת, שהניעה את מתג מדדי המשתמשים ב-AdMob, תופסק בתחילת 2024. כדי להמשיך לאסוף מדדי משתמשים ב-AdMob, צריך לקשר את האפליקציה ב-AdMob ל-Firebase ולשלב את Google Analytics for Firebase SDK באפליקציה.
שינויים בהצגת המודעות במסך מלא
השינויים הבאים משפיעים על הפורמטים השונים של המודעות:
- מודעות בפתיחת האפליקציה
- פרסומת מרווח ביניים
- ההטבה הופעלה
- מודעת מעברון מתגמלת
הפרמטר של בקר הצפייה ב--canPresentFromRootViewController:error:
וב--presentFromRootViewController:
יכול להיות null. אם לא מעבירים את הערך n, המודעה תוצג מהבקר העליון בהיררכיה של בקר התצוגה.
שיטות שהוסרו
השיטות הבאות הוסרו.
סוג v11.0.0 | שיטה | הערות |
---|---|---|
GADAppOpenAd | load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) |
במקומו צריך להשתמש ב-load(withAdUnitID adUnitID: String, request: GADRequest?) . |
GADMediationBannerAdEventDelegate | willBackgroundApplication() |
אין החלפה. |
GADMediationInterstitialAdEventDelegate | willBackgroundApplication() |
אין החלפה. |
GADMediationNativeAdEventDelegate | willBackgroundApplication() |
אין החלפה. |
GADMediationRewardedAdEventDelegate | didRewardUser(with reward: GADAdReward) |
במקומו צריך להשתמש ב-didRewardUser() . |
GADMediatedUnifiedNativeAdNotificationSource | mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) |
אין החלפה. |
GADRequestConfiguration | setSameAppKeyEnabled(_ enabled: Bool) |
במקום זאת, השתמשו ב-setPublisherFirstPartyIDEnabled(_ enabled: Bool) . |
tagForUnderAge(ofConsent underAgeOfConsent: Bool) |
במקום זאת, יש להשתמש בנכס tagForUnderAgeOfConsent . |
|
tag(forChildDirectedTreatment childDirectedTreatment: Bool) |
במקום זאת, יש להשתמש בנכס tagForChildDirectedTreatment . |
הנכסים הוסרו
המאפיינים הבאים הוסרו.
דרגה v11.0.0 | מאפיין (property) | הערות |
---|---|---|
GADMediationAdConfiguration | hasUserLocation | אין החלפה. |
userLatitude | ||
userLongitude | ||
userLocationAccuracyInMeters | ||
childDirectedTreatment | במקומו צריך להשתמש ב-GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment . |
|
GADResponseInfo | adNetworkClassName | במקום זאת, יש להשתמש ב-adNetworkClassName מ-loadedAdNetworkResponseInfo . |
הוסר GADAdFormatUnknown
בוצעה הסרה של GADAdFormatUnknown
ללא החלפה.
שינויים ברישום של גרסת ה-SDK ביומן
גרסה 11.0.0 מסירה את sdkVersion
. על מנת לתעד את הגרסה של Google Mobile Ads SDK, צריך להשתמש במקום זאת ב-versionNumber
.
גרסה 10.0.0
GADMobileAds.sharedInstance().sdkVersion
גרסה 11.0.0
GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)
שינויים בטיפול בשגיאות GADAdLoader
החל מגרסה 11.0.0, GADAdLoader
לא שולח בקשה להצגת מודעה אם delegate
שלה לא תואם לפרוטוקול ההאצלה של סוגי המודעות המבוקשים. בעבר, הצגת המודעות נכשלה אחרי שליחת הבקשה להצגת מודעה.
שינויים בהתנהגות הבדיקה
אפשר לעיין בטבלה שבה מוצגים התנאים המעודכנים למקרים שבהם המאפיינים הבאים מחזירים את הערך true
.
מחלקה | מאפיין (property) |
---|---|
GADMediationAdConfiguration | isTestRequest |
GADCustomEventRequest | isTesting |
v10.0.0 | v11.0.0 |
|
|
מעבר מגרסה 9 לגרסה 10
הפסקת ההצגה של המודעות ב-iOS 11
בגרסה 10.0.0 של Google Mobile Ads SDK מוצגות מודעות רק במכשירים עם iOS מגרסה 12 ואילך.
שדרוג לגרסה 10.0.0 של Google Mobile Ads SDK לא יקטע את האפליקציה במכשירי iOS 11 ו-iOS 10, אבל לא יוצגו מודעות במכשירים האלה.
הדרישה למזהה אפליקציה ב-Ad Manager
עכשיו מזהה האפליקציה ב-Ad Manager נדרש עכשיו ב-Info.plist
בכל האפליקציות ב-Ad Manager, ונדרש הפורמט ca-app-pub-################~##########
. לפרטים נוספים, ראו עדכון ה-Info.plist.
דרישה של GoogleAppMeasurement.xcframework
עכשיו צריך להתקין את GoogleAppMeasurement.xcframework בכל האפליקציות של Ad Manager. אם מתקינים את Google Mobile Ads SDK דרך Cocoapods או Swift Package Manager, אין צורך לבצע פעולה נוספת. אם אתם מתקינים את frameworks באופן ידני, קראו את המאמר הורדה ידנית לקבלת פרטים נוספים.
אין יותר תמיכה במבנה עם קוד ביט
מעכשיו, כדי לשלב את Google Mobile Ads SDK צריך להשבית את ה-bitcode באפליקציות לנייד.
סוגים שהוסרו
תיאור | הערות |
---|---|
GADGender | אין החלפה. |
GADMRewardBasedVideoAdNetworkAdapterProtocol | כל המתאמים של תהליך בחירת הרשת ליחידת מודעות מתגמלות הרשומים ב- Choose Networks הפסיקו להשתמש בפרוטוקולים האלה במשך יותר משנה. שימוש ב- GADMediationAdapter לתהליך בחירת הרשת ולאירועים בהתאמה אישית. |
GADMRewardBasedVideoAdNetworkConnectorProtocol |
הנכסים הוסרו
המאפיינים הבאים הוסרו ללא החלפה.
רמה 10.0.0 | נכס |
---|---|
GADMediationAdRequest | userBirthday |
userGender | |
userHasLocation | |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription | |
GADCustomEventRequest | userHasLocation |
userLatitude | |
userLongitude | |
userLocationAccuracyInMeters | |
userLocationDescription |
מעבר מגרסה 8 לגרסה 9
הפסקת ההצגה של מודעות ב-iOS 10
גרסת iOS המינימלית שנתמכת בגרסה 9.0.0 של Google Mobile Ads SDK היא iOS 11.
שדרוג לגרסה 9.0.0 של Google Mobile Ads SDK לא יכבה את האפליקציה במכשירי iOS 10, אבל לא יוצגו מודעות במכשירים האלה.
אכיפה מחמירה יותר של הפקדים בשורת הסטטוס
החל מגרסה 9.0.0, כשמציגים מודעות בפורמט מסך מלא, באפליקציה צריך לוודא שאפשר לשלוט בהצגת שורת הסטטוס. במקרה שהפעולה לא תתבצע בהצלחה, תופיע ביומנים הודעת שגיאה.
בהתאם לפריסה הספציפית של בקרי התצוגה באפליקציה, יכול להיות שלא צריך לבצע שינויים כדי לוודא זאת. כדאי לשקול אם צריך להגדיר את המאפיין childViewControllerForStatusBarHidden
בrootViewController
של המודעה.
שינוי השם של adDidShowFullScreenContent: ל-adWillpresentFullScreenContent:
אין שינוי בהתנהגות. שיטת הענקת הגישה מופעלת ממש לפני שהמודעה עומדת להופיע, ולכן השם של השיטה החדשה משקף בצורה טובה יותר את הפונקציונליות שלה.
הסרת API של הגדרת מיקום ב-GADRequest
- (void)setLocationWithLatitude:longitude:accuracy:
נמחק מ-GADRequest
מפני ש-Google לא משתמשת בנתוני מיקום כדי למקד מודעות. שימוש בממשקי API של צד שלישי כדי לספק את המידע לרשתות המודעות של הצד השלישי, במקרה הצורך.
הוצאה משימוש של ממשקים של אירועים מותאמים אישית
אירועים מותאמים אישית מאפשרים לבעלי אפליקציות שמשתמשים ב Ad Manager תהליך בחירת הרשת (Mediation) להוסיף את תהליך בחירת הרשת (Mediation) ב-Waterfall עבור רשת מודעות שאינה אחת מרשתות המודעות הנתמכות.
כל הפרוטוקולים של אירועים מותאמים אישית הוצאו משימוש. במקום זאת, כדאי להשתמש בפרוטוקולים הקיימים
GADMediationAdapter
ו-GADMediationAdEventDelegate
כדי להשיג את אותן פונקציות. השינוי הזה משפר את הבהירות ומאפשר לך ליצור אירועים מותאמים אישית למודעות מתגמלות ולמודעות מעברון גלילה שלא היו זמינות קודם לכן.
ממשקי API
בטבלה הבאה מפורטים ממשקי ה-API המתאימים של המתאמים לתהליך בחירת הרשת אל ממשקי API של אירועים מותאמים אישית, שבהם יש להשתמש החל מגרסה 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBanner GADCustomEventInterstitial GADCustomEventNativeAd |
GADMediationAdapter | GADMediationBannerAd GADMediationInterstitialAd GADMediationInterscrollerAd GADMediationRewardedAd GADMediationNativeAd |
delegate
|
מקבל הגישה מוחזר על ידי המטפל להשלמת הטעינה של כל פונקציית טעינה של מחלקה GADMediationAdapter
|
|
-init |
-init |
|
-requestBannerAd:parameter: |
-loadBannerForAdConfiguration: |
|
-requestInterstitialAdWith |
-loadInterstitialFor |
|
-requestNativeAdWithParameter:
|
-loadNativeAdFor |
|
לא רלוונטי | -loadInterscrollerAdFor |
|
לא רלוונטי | -loadRewardedAdFor |
|
-presentFromRootViewController:
|
-presentFromViewController: |
|
-handlesUserClicks |
-handlesUserClicks |
|
-handlesUserImpressions |
-handlesUserImpressions |
שיטות להאצלת זכויות
בטבלה הבאה מפורטות השיטות המתאימות להאצלת אירועים במודעות בתהליך בחירת הרשת, בשיטות מותאמות אישית להענקת גישה לאירועים, שבהן צריך להשתמש החל מגרסה 9.0.0.
v8 | v9 | |
---|---|---|
GADCustomEventBannerOwner GADCustomEventInterstitial() GADCustomEventNativeAd בוצע |
GADMediationAdEventDelegate | מודעת GADMediation |
-customEventBanner:didReceiveAd: -customEventInterstitialDidReceiveAd:
|
סטטוס טעינת המודעות נכלל ב-handler של השלמת הטעינה של
כל פונקציית טעינה במחלקה GADMediationAdapter
|
|
-customEventBanner:didFailAd: -customEventInterstitial:didFailAd:
|
||
-customEventBannerWasClicked: -customEventInterstitialWasClicked:
|
-reportClick |
|
-customEventBannerWill -customEventInterstitialWill
|
-willPresentFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willDismissFullScreenView |
|
-customEventBannerDid -customEventInterstitialDid
|
-didDismissFullScreenView |
|
-customEventBannerWill -customEventInterstitialWill
|
-willBackgroundApplication |
|
viewControllerFor |
-[GADMediationBannerAd view] |
שיטות וקבועים אחרים שהוסרו/הוחלפו
שינויים ב-method, בקבוע או בנכס | |
---|---|
קבועים (kGAD- ) עם קידומת
|
הנושא הוסר. שימוש בקבועים עם קידומת GAD- .
|
GADAdNetworkResponseInfo
|
credentials הוסרו. במקומה צריך להשתמש במדיניות adUnitMapping .
|
GAMRequest
|
האפשרות kGAMSimulatorID ב-GAMRequest הוצאה משימוש.
במקום זאת, יש להשתמש בתוסף GADSimulatorID ב-GADRequestConfiguration .
|
GADCustomNativeAd
|
האפשרות mediaView ב-GADCustomNativeAd הוצאה משימוש.
במקומה צריך להשתמש במדיניות mediaContent .
|
ממשקי API לרכישה מתוך האפליקציה ב-GoogleMobileAds |
הוסרו inAppPurchase ממשקי API ב-GoogleMobileAds .
|
מעבר מגרסה 7 לגרסה 8
גרסה 8.0.0 של Google Mobile Ads SDK כוללת כמה שינויים משמעותיים, וגם כמה שינויי שמות והסרת ממשקי API.
עדכונים ב-API בפורמט מסך מלא
החל מגרסה 8.0.0, מודעות מעברון ומודעות מתגמלות חולקות סגנון מודעה כללי במסך מלא כדי לשפר את העקביות. לממשקי ה-API החדשים להצגת מודעות במסך מלא יש שתי הבדלים מהותיים לעומת ממשקי ה-API של מודעות שמוצגות במסך מלא מגרסה 7:
שיטת מחלקה סטטית
load
.הגישה הקודמת לטעינה/הצגה של מודעה במסך מלא היא:
- יוצרים מופע של אובייקט מודעה ומחזיקים בו הפניה.
- יש להקצות משתמש בעל גישה שיטפל בטעינה ויציג את הקריאה החוזרת (callback).
- טעינת מודעה.
- אפשר להשתמש ב
isReady
כדי לבדוק אם המודעה נטענת. - מציגים את המודעה.
בגרסה 8, הגישה משתנה מעט. קריאה חוזרת (callback) מסוג טעינה כבר לא מהווה חלק מ-פריטים שהוענקו. במקום זאת, הם מועברים ל-method
load
כגורם handler להשלמה:- קוראים לשיטת טעינה סטטית במחלקה של המודעה וספקו handler להשלמת טעינה.
- בקריאה החוזרת לצורך השלמת הטעינה, שמרו הפניה למודעה שנטענה שמוחזרת.
- יש להקצות משתמש בעל גישה שיטפל בקריאות חוזרות (callback).
- מציגים את המודעה.
הגישה החדשה מספקת את היתרונות הבאים:
- אף פעם לא תהיה לכם הפניה למודעה שלא נטענה.
- אין צורך ללחוץ לחיצה ארוכה על אובייקט של מודעה בזמן שהוא נטען.
אירועי מודעות עקביים.
סוג האירוע ממשק API קיים API של גרסה 8 טעינת אירועים GADInterstitialDelegate
אוGADRewardedAdDelegate
GAMInterstitialAdLoadCompletionHandler
אוGADRewardedAdLoadCompletionHandler
אירועי מצגות GADFullScreenContentDelegate
בעבר, כדי להאזין לאירועי מודעות, הייתם רושמים מחלקה שמטמיעה את הפרוטוקול
GADInterstitialDelegate
בנכס הענקת גישה במודעת מעברון, או רושמים מחלקה שמטמיעה את הפרוטוקולGADRewardedAdDelegate
בנכס הענקת גישה במודעה מתגמלת, בהתאם לפורמט שבו אתם משתמשים. למשתמש הזה היו שיטות שקשורות גם למחזור החיים של הטעינה וגם למחזור החיים של הצגת המודעה.בגרסה 8, אירועי טעינה ומצגות הם שני אירועים נפרדים. מעכשיו אפשר לרשום
GADFullScreenContentDelegate
בכל זמן לפני הצגת המודעה, במקום לחייב הרשאת גישה יחידה לפני טעינת המודעה. אירועי טעינת מודעות, שהם ספציפיים לכל פורמט, עוברים ל-handler היחיד של השלמת הטעינה שמועבר בשיטת הטעינה.
פרסומת מרווח ביניים
טעינת המודעה
קטעי הקוד שבהמשך מראים איך לטעון מודעת מעברון ולהאזין לאירועים שבהם המודעה מצליחה או נכשלת.
v7
Swift
import GoogleMobileAds import UIKit class ViewController: UIViewController, GADInterstitialDelegate { var interstitial: DFPInterstitial! override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/6499/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)") } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) DFPInterstitial *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:@"/6499/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]); }
v8
Swift
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 } ) } }
Objective-C
@import GoogleMobileAds; @import UIKit; @interface ViewController ()@property(nonatomic, strong) GAMInterstitialAd *interstitial; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/6499/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; }]; }
מודעה ברשת המדיה
v7
Swift
func showInterstitial() { ... if interstitial.isReady { interstitial.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showInterstitial: { ... if (self.interstitial.isReady) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
v8
Swift
func showInterstitial() { ... if let ad = interstitial { ad.present(fromRootViewController: self) } else { print("Ad wasn't ready") } }
Objective-C
- (void)showInterstitial: { ... if (self.interstitial) { [self.interstitial presentFromRootViewController:self]; } else { NSLog(@"Ad wasn't ready"); } }
אירועים של מודעות מצגת
קטעי הקוד הבאים מראים איך לטפל בקריאות חוזרות (callback) במקרים שבהם המודעה מוצגת (בהצלחה או בכישלון) ומתי היא נסגרת.
v7
Swift
override func viewDidLoad() { super.viewDidLoad() interstitial = DFPInterstitial(adUnitID: "/6499/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.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:"/6499/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."); }
v8
Swift
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.") }
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; GAMRequest *request = [GAMRequest request]; [GAMInterstitialAd loadWithAdUnitID:@"/6499/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."); }
ההטבה הופעלה
טעינת המודעה
v7
Swift
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.") } } } }
Objective-C
@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."); } }]; }
v8
Swift
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 } ) } }
Objective-C
@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; }
הצגת המודעה והצגת התגמול
כשמשתמשים במודעות מתגמלות, צריך לטפל באירוע כשמשתמש מקבל תגמול. בגרסה 7 של GADRewardedAd
API, אפשר להטמיע את rewardedAd:userDidEarnReward:
כחלק מפרוטוקול GADRewardedAdDelegate
.
בגרסה 8, צריך להטמיע את GADUserDidEarnRewardHandler
כדי להציג את המודעה.
v7
Swift
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. }
Objective-C
- (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. }
v8
Swift
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") } }
Objective-C
- (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
לשיטה שמציגה את המודעה. באמצעות GADRewardedAd
API אפשר להגדיר את GADFullscreenContentDelegate
כנכס במודעה לפני הצגת המודעה.
v7
Swift
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).") }
Objective-C
- (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."); }
v8
Swift
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).") }
Objective-C
- (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 API
ה-API החדש יותר של GADRewardedAd
הושק לראשונה במרץ 2019, והוא ה-API המועדף לשימוש כבר במשך יותר מ-18 חודשים. יש בו יותר שיפורים בהשוואה ל-API הקודם של GADRewardedBasedVideoAd
, כולל האפשרות לטעון יותר ממודעה מתגמלת אחת בכל פעם.
ממשק ה-API הקודם של GADRewardedBasedVideoAd
הוסר בגרסה 8.0.0 של SDK.
הוצאה משימוש של מודעות באנר חכמות לטובת מודעות באנר מותאמות
מודעות באנר חכמות הוצאו משימוש והוחלפו במודעות באנר מותאמות. מודעות באנר מותאמות מספקות ביצועים טובים יותר וגמישות רבה יותר בהגדרת רוחב המודעה. אם אתם מעדיפים להמשיך להשתמש במודעות באנר ברוחב מלא, עדיין אפשר לעשות זאת בעזרת מודעות באנר מותאמות, כפי שמוצג בקטע הקוד הבא:
Swift
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) } }
Objective-C
@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
יציאה מהסרת הקריאה החוזרת (callback) מהאפליקציה
willLeaveApplication
callback לכל הפורמטים של המודעות הוסר לטובת השיטות
applicationDidEnterBackground:
ו-sceneDidEnterBackground:
. כשמשתמשים בממשקי API ברמת מערכת ההפעלה, מקבלים התראה בכל פעם שמשתמשים יוצאים מהאפליקציה, גם אם הסיבה לכך היא אינטראקציה עם מודעה וגם אם לא.
לתשומת ליבכם: הקריאה החוזרת willLeaveApplication
מעולם לא הייתה אמורה לשמש כגורם לטיפול בקליקים על מודעות, והסתמכות על הקריאה החוזרת הזו לדיווח על קליקים לא הניבה ערך מדויק. לדוגמה, קליק על הסמל AdChoices
שהפעיל דפדפן חיצוני הפעיל את הקריאה החוזרת, אבל לא נספר קליק.
שינויי שמות של כיתות
בטבלה הבאה מפורטים שמות מחלקות ספציפיים שהשתנו או הוסרו בגרסה 8. בקצרה:
- השם של כל הכיתות שקשורות אל
GADUnifiedNativeAd
השתנה ל-GADNativeAd
. GADRewardBasedVideoAd
,GADNativeExpressAdView
ו-GADInstreamAd
הוסרו.- כל המחלקות עם הקידומת
DFP
הוחלפו בקידומתGAM
.
גרסה 7.68.0 רמה | רמה 8.0.0 |
---|---|
DFPBannerView | GAMBannerView |
DFPBannerViewOptions | GAMBannerViewOptions |
DFPInterstitial | מודעת מעברון ב-GAM |
DFPRequest | GAMRequest |
GADRequestError | NSError |
GADUnifiedNativeAdView | GADNativeAdView |
GADUnifiedNativeAd | מודעה מותאמת ב-GAD |
GADUnifiedNativeAdAssetIdentifiers | GADNativeAdAssetIdentifiers |
GADUnifiedNativeAdDelegate | GADNativeAdDelegate |
GADUnifiedNativeAdUnconfirmedClickDelegate | GADNativeAdUnconfirmedClickDelegate |
GADNativeCustomTemplateAd | GADCustomNativeAd |
GADNativeCustomTemplateAdLoaderDelegate | GADCustomNativeAdLoaderDelegate |
GADNativeAdDelegate | GADCustomNativeAdDelegate |
GADInAppPurchase | הוסרה |
GADInterstitial | מודעת מעברון ב-GAD |
GADNativeExpressAdView | הוסרה |
מודעת וידאו של GADRewardBased | הוסרה |
מודעת וידאו In-stream ב-GAD | הוסרה |
GADInstreamAdView | הוסרה |
שיטות שהוסרו/הוחלפו
הטבלה הבאה מפרטת את השינויים הספציפיים בגרסה 8. בקצרה:
- שיטות ונכסים שהוצאו משימוש בעבר הוסרו.
- הוסרו
-willLeaveApplication:
שיטות להאצלה לכל הפורמטים. - שם הסיווג של רשת המודעות הועבר לנכס
GADResponseInfo
. - מזהה מכשיר הבדיקה הועבר לנכס
GADRequestConfiguration
.
גרסה 7.68.0 רמה | API גרסה 7.68.0 | API גרסה 8.0.0 | הערות |
---|---|---|---|
מודעות GADMobile | +configureWithApplicationID: | -startWithCompletionHandler: | מזהה האפליקציה מוגדר עכשיו ב-Info.plist. |
+disableAutoInApp |
-disableAutoInApp |
||
+השבתה של SDKCrashReporting | -השבתה של SDKCrashReporting | ||
GADRequest | testDevices | GADRequestConfiguration |
המאפיין testDeviceIdentifiers חל על כל הבקשות להצגת מודעות, ואילו הנכס הישן testDevices היה מוגדר לפי בקשה. |
gender | הוסרה | ||
יום הולדת | הוסרה | ||
+sdkVersion | GADMobileAds.sharedInstance |
||
-setBirthday |
הוסרה | ||
-setLocationWithDescription: | -setLocationWith |
||
-tagForChildDirectedTreatment: | [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment] | ||
GADErrorCode | kGADError* | GADError* | הקידומת k מוסרת מכל הקבועים של קוד השגיאה.
|
GADBannerView | hasAutoRefreshed | autoloadEnabled | |
inAppPurchaseDelegate | הוסרה | ||
mediatedAdView | הוסרה | ||
adNetworkClassName | responseInfo |
||
DFPBannerView | -setValidAdSizesWithSizes: | -setValidAdSizes: | |
DFPBannerViewOptions | -adSizeextension | הוסרה | |
GADBannerViewDelegate | -adViewDidReceiveAd: | -bannerViewDidReceiveAd: | |
-adView:didFailToReceive |
-bannerView:didFailToReceive |
||
-adViewWillpresentScreen: | -bannerViewWillpresentScreen: | ||
-adViewWillDismissScreen: | -bannerViewWillDismissScreen: | ||
-adViewDidDismissScreen: | -bannerViewDidDismissScreen: | ||
-adViewWillleaveApplication: | הוסרה | ||
GADNativeCustomTemplateAd | templateID | GADCustomNativeAd.formatID | |
-performClickOnAssetWithKey: |
-performanceClickOnAssetWithKey: | ||
GADNativeAdImageAd |
preferredImageOrientation | GADNativeAdMediaAdOptions |
|
GADInterstitial | inAppPurchaseDelegate | הוסרה | |
isReady | הוסרה | במקומו צריך להשתמש ב-canpresentFrom |
|
hasBeenUsed | הוסרה | ||
-init | -initWithAdUnitID: | ||
-setAdUnitID: | -initWithAdUnitID: | ||
adNetworkClassName | responseInfo |
||
-interstitialWill |
הוסרה | ||
GADUnifiedNativeAd | videoController | mediaContent.videoController | |
adNetworkClassName | responseInfo |