SDK टूल का माइग्रेशन

इस पेज पर मौजूदा और पिछले वर्शन के लिए माइग्रेशन की जानकारी दी गई है.

10 से v11 पर माइग्रेट करें

डिप्लॉयमेंट टारगेट के लिए तय किया गया कम से कम इस्तेमाल

कम से कम डिप्लॉयमेंट टारगेट को बढ़ाकर iOS 12 कर दिया गया है.

कम से कम Xcode वर्शन

Xcode के सबसे कम वर्शन वाले वर्शन को 15.1 कर दिया गया है.

iOS 12 पर विज्ञापन दिखना बंद हो गए हैं

Google Mobile Ads SDK के वर्शन 11.0.0 में सिर्फ़ iOS 13 और इसके बाद के वर्शन वाले डिवाइसों पर विज्ञापन दिखाए जाते हैं.

GoogleAppमेज़रमेंट डिपेंडेंसी हटाई गई

वर्शन 11.0.0 में, GoogleAppMeasurement पर निर्भरता को हटा दिया गया है. AdMob में उपयोगकर्ता मेट्रिक टॉगल को चलाने वाली इस डिपेंडेंसी को 2024 की शुरुआत में बंद कर दिया जाएगा. AdMob में उपयोगकर्ता मेट्रिक इकट्ठा करना जारी रखने के लिए, अपने AdMob ऐप्लिकेशन को Firebase से लिंक करें. साथ ही, Firebase के लिए Google Analytics SDK टूल को अपने ऐप्लिकेशन में इंटिग्रेट करें.

फ़ुल-स्क्रीन विज्ञापन प्रज़ेंटेशन में बदलाव

ये बदलाव अलग-अलग विज्ञापन फ़ॉर्मैट पर असर डालते हैं:

  • ऐप्लिकेशन खोलने पर दिखने वाला विज्ञापन
  • मध्यवर्ती
  • इनाम दिया गया
  • इनाम वाले इंटरस्टीशियल विज्ञापन

-canPresentFromRootViewController:error: और -presentFromRootViewController: में व्यू कंट्रोलर पैरामीटर शून्य किया जा सकता है. अगर शून्य पास होता है, तो विज्ञापन व्यू कंट्रोलर के क्रम में सबसे ऊपर मौजूद व्यू कंट्रोलर से दिखाया जाता है.

तरीके हटाए गए

यहां दिए गए तरीके हटा दिए गए हैं.

v11.0.0 का टाइप तरीका ज़रूरी जानकारी
GADAppOpenविज्ञापन 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 क्लास प्रॉपर्टी ज़रूरी जानकारी
GADMediationAdConfiguration hasUserLocation कोई रिप्लेसमेंट नहीं.
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment इसके बजाय, GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment का इस्तेमाल करें.
GADResponseInfo adNetworkClassName इसके बजाय, loadedAdNetworkResponseInfo के adNetworkClassName का इस्तेमाल करें.

हटाया गया GADAdFormatअज्ञात

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 के मिलने पर, अपडेट की गई शर्तें दिखती हैं.

कक्षा प्रॉपर्टी
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • testDeviceIdentifiers में, साफ़ तौर पर इस डिवाइस को टेस्ट डिवाइस के तौर पर बताया गया है.
  • testDeviceIdentifiers में, साफ़ तौर पर इस डिवाइस को टेस्ट डिवाइस के तौर पर बताया गया है.
  • यह एक सिम्युलेटर है.
  • Ad Manager यूज़र इंटरफ़ेस (यूआई) में इस डिवाइस को साफ़ तौर पर टेस्ट डिवाइस के तौर पर बताया गया है.

वर्शन 9 से v10 पर माइग्रेट करना

iOS 11 पर विज्ञापन दिखना बंद हो गए हैं

Google Mobile Ads SDK के वर्शन 10.0.0 में सिर्फ़ iOS 12 और इसके बाद के वर्शन वाले डिवाइसों पर विज्ञापन दिखाए जाते हैं.

Google Mobile Ads SDK के 10.0.0 वर्शन पर अपग्रेड करने से, iOS 11 और iOS 10 डिवाइसों पर आपका ऐप्लिकेशन काम नहीं करेगा. हालांकि, उन डिवाइसों पर कोई विज्ञापन नहीं दिखाया जाएगा.

Ad Manager ऐप्लिकेशन आईडी की ज़रूरी शर्तें

अब Info.plist में सभी Ad Manager ऐप्लिकेशन के लिए Ad Manager ऐप्लिकेशन आईडी होना ज़रूरी है. साथ ही, ca-app-pub-################~########## फ़ॉर्मैट भी होना ज़रूरी है. ज़्यादा जानकारी के लिए, अपनी Info.plist अपडेट करें देखें.

GoogleAppमेज़रमेंट.xcframework की ज़रूरत

अब सभी Ad Manager ऐप्लिकेशन के लिए GoogleAppमेज़रमेंट.xcframework ज़रूरी है. अगर Cocoapods या Swift Package Manager की मदद से Google Mobile Ads SDK इंस्टॉल किया जाता है, तो आपको कुछ और करने की ज़रूरत नहीं है. अगर फ़्रेमवर्क को मैन्युअल तरीके से इंस्टॉल किया जाता है, तो ज़्यादा जानकारी के लिए मैन्युअल डाउनलोड देखें.

बिटकोड के साथ बिल्डिंग अब काम नहीं करती

अब आपके मोबाइल ऐप्लिकेशन में बिटकोड को बंद करने के लिए, Google Mobile Ads SDK टूल को इंटिग्रेट करना ज़रूरी है.

हटाए गए टाइप

टाइप ज़रूरी जानकारी
GADGender कोई रिप्लेसमेंट नहीं.
GADMRewardBasedVideoAdNetworkAdapterProtocol Select Network पर मौजूद, इनाम वाले सभी मीडिएशन अडैप्टर ने एक साल से ज़्यादा समय से इन प्रोटोकॉल का इस्तेमाल करना बंद कर दिया है. मीडिएशन और कस्टम इवेंट के लिए, GADMediationAdapter का इस्तेमाल करें.
GADMRewardBasedVideoAdNetworkConnectorProtocol

प्रॉपर्टी हटाई गईं

नीचे दी गई प्रॉपर्टी हटा दी गई हैं और उनकी जगह किसी और प्रॉपर्टी का इस्तेमाल नहीं किया जा सकता.

v10.0.0 क्लास प्रॉपर्टी
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

वर्शन 8 से v9 पर माइग्रेट करें

iOS 10 पर विज्ञापन दिखना बंद हो गए हैं

Google Mobile Ads SDK के 9.0.0 वर्शन पर काम करने वाला iOS का कम से कम वर्शन iOS 11 है.

Google Mobile Ads SDK के 9.0.0 वर्शन पर अपग्रेड करने से, iOS 10 डिवाइसों पर आपका ऐप्लिकेशन काम नहीं करेगा. हालांकि, उन डिवाइसों पर कोई विज्ञापन नहीं दिखाया जाएगा.

स्टेटस बार कंट्रोल का सख्ती से पालन

9.0.0 और उसके बाद के वर्शन में, फ़ुल-स्क्रीन फ़ॉर्मैट वाले विज्ञापन प्रज़ेंट करने पर, आपके ऐप्लिकेशन को यह पक्का करना होगा कि विज्ञापन, स्टेटस बार को दिखाए जाने की कंट्रोल को कंट्रोल कर सकें. ऐसा न करने पर, आपको लॉग में गड़बड़ी का मैसेज दिखेगा.

आपके ऐप्लिकेशन में व्यू कंट्रोलर के खास लेआउट के आधार पर, हो सकता है कि आपको इसे पक्का करने के लिए कोई बदलाव करने की ज़रूरत न पड़े. तय करें कि आपको अपने विज्ञापन के rootViewController पर childViewControllerForStatusBarHidden प्रॉपर्टी सेट करनी है या नहीं.

विज्ञापन का नाम बदलें adDidpresentFullScreenContent: to adwillpresentFullScreenContent:

ऐप्लिकेशन के काम करने के तरीके में कोई बदलाव नहीं हुआ है. विज्ञापन दिखाने के तरीके को, विज्ञापन दिखाने से ठीक पहले शुरू किया जाता है. इसलिए, नए तरीके के नाम से पता चलता है कि यह तरीका कैसे काम करता है.

GADRequest पर, जगह की जानकारी की सेटिंग वाला एपीआई हटाएं

- (void)setLocationWithLatitude:longitude:accuracy: को GADRequest से मिटा दिया गया है, क्योंकि Google, विज्ञापन दिखाने के लिए जगह की जानकारी के डेटा का इस्तेमाल नहीं करता. अगर ज़रूरी हो, तो तीसरे पक्ष की विज्ञापन नेटवर्क कंपनी को जानकारी देने के लिए तीसरे पक्ष के एपीआई इस्तेमाल करें.

कस्टम इवेंट के इंटरफ़ेस को बंद किया जा रहा है

कस्टम इवेंट, किसी ऐसी विज्ञापन नेटवर्क कंपनी के लिए वॉटरफ़ॉल मीडिएशन जोड़ने के लिए, Ad Manager मीडिएशन की सुविधा देता है जो काम करने वाले विज्ञापन नेटवर्क में शामिल नहीं है.

सभी कस्टम इवेंट प्रोटोकॉल हटा दिए गए हैं. इसके बजाय, उन सुविधाओं के लिए मौजूदा GADMediationAdapter और GADMediationAdEventDelegate प्रोटोकॉल का इस्तेमाल करें. इस बदलाव से ज़्यादा जानकारी मिलती है. साथ ही, इनाम वाले विज्ञापनों और इंटरस्क्रोलर विज्ञापनों के लिए कस्टम इवेंट बनाए जा सकते हैं, जो पहले उपलब्ध नहीं थे.

API

नीचे दी गई टेबल में, संबंधित मीडिएशन अडैप्टर एपीआई से कस्टम इवेंट एपीआई की सूची दी गई है. इन एपीआई का इस्तेमाल वर्शन 9.0.0 से शुरू करके किया जाना चाहिए.

v8 v9
GADCustomEventBanner
GADCustomEvent विक्रेता
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationMediaAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate GADMediationAdapter क्लास के हर लोड फ़ंक्शन के लोड पूरा होने वाले हैंडलर से डेलिगेट दिखाया जाता है
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
लागू नहीं -loadInterscrollerAdForAdConfiguration:completionHandler:
लागू नहीं -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

डेटा ऐक्सेस करने के तरीके

नीचे दी गई टेबल में, कस्टम इवेंट डेलिगेट के तरीकों से जुड़े मीडिएशन विज्ञापन इवेंट के डेलिगेट के तरीकों की सूची दी गई है. इनका इस्तेमाल वर्शन 9.0.0 से शुरू करके किया जाना चाहिए.

v8 v9
GADCustomEventBanner सुंदर
GADCustomEventदियों के बैज
GADCustomEventNativeAd शरीर के सदस्य
GADMediationAdEventDelegate GADमीडिएशन विज्ञापन
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
विज्ञापन लोड होने की स्थिति, GADMediationAdapter क्लास में हर लोड फ़ंक्शन के लोड पूरा होने वाले हैंडलर में शामिल की जाती है
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

हटाए गए/बदले गए अन्य तरीके और कॉन्सटेंट

मेथड, कॉन्सटेंट या प्रॉपर्टी में बदलाव
पहले से तय किए गए kGAD- स्थिरांक हटाया गया. GAD- से पहले वाले कॉन्सटेंट का इस्तेमाल करें.
GADAdNetworkResponseInfo credentials को हटा दिया गया. इसके बजाय, adUnitMapping का इस्तेमाल करें.
GAMRequest GAMRequest में kGAMSimulatorID के इस्तेमाल पर रोक लगा दी गई है. इसके बजाय, GADRequestConfiguration में GADSimulatorID का इस्तेमाल करें.
GADCustomNativeAd GADCustomNativeAd में mediaView के इस्तेमाल पर रोक लगा दी गई है. इसके बजाय, mediaContent का इस्तेमाल करें.
GoogleMobileAds में इन-ऐप्लिकेशन खरीदारी के एपीआई GoogleMobileAds में मौजूद inAppPurchase एपीआई हटाए गए.

वर्शन 7 से v8 पर माइग्रेट करें

Google Mobile Ads SDK के वर्शन 8.0.0 में कुछ बड़े बदलाव किए गए हैं. साथ ही, कुछ एपीआई को बदले गए और हटाए भी गए हैं.

फ़ुल-स्क्रीन फ़ॉर्मैट वाले एपीआई के अपडेट

वर्शन 8.0.0 से, पेज पर अचानक दिखने वाले विज्ञापन और इनाम वाले विज्ञापन, एक सामान्य फ़ुल स्क्रीन विज्ञापन स्टाइल शेयर करते हैं, ताकि ज़्यादा समानता रहे. इन नए फ़ुल-स्क्रीन विज्ञापन एपीआई को, वर्शन 7, फ़ुल-स्क्रीन विज्ञापन एपीआई के मुकाबले दो बड़ी खूबियां हैं:

  1. स्टैटिक क्लास का तरीका load.

    किसी फ़ुल-स्क्रीन विज्ञापन को लोड करने/दिखाने के लिए, पिछला तरीका यहां बताया गया है:

    1. कोई विज्ञापन ऑब्जेक्ट इंस्टेंस बनाएं और उसका रेफ़रंस होल्ड करें.
    2. लोड को हैंडल करने और कॉलबैक दिखाने के लिए, कोई डेलिगेट असाइन करें.
    3. कोई विज्ञापन लोड करें.
    4. देखें कि isReady का इस्तेमाल करके विज्ञापन लोड होता है या नहीं.
    5. विज्ञापन दिखाएं.

    वर्शन 8 में, काम करने का तरीका थोड़ा बदलता है. लोड कॉलबैक अब डेलिगेट का हिस्सा नहीं हैं. इसके बजाय, उन्हें load तरीके में पूरा होने वाले हैंडलर के तौर पर पास किया जाता है:

    1. विज्ञापन क्लास पर किसी स्टैटिक लोड के तरीके को कॉल करें और लोड पूरा होने से जुड़ा हैंडलर दें.
    2. लोड पूरा होने के कॉलबैक में, लोड किए गए विज्ञापन का रेफ़रंस रखें.
    3. शो कॉलबैक को मैनेज करने वाला प्रतिनिधि असाइन करें.
    4. विज्ञापन दिखाएं.

    नए तरीके से ये फ़ायदे मिलते हैं:

    • आपको कभी भी किसी ऐसे विज्ञापन का संदर्भ नहीं मिलेगा जो लोड न हुआ हो.
    • लोड होते समय आपको किसी विज्ञापन ऑब्जेक्ट को पकड़कर रखने की ज़रूरत नहीं है.
  2. लगातार विज्ञापन इवेंट.

    इवेंट किस तरह का है मौजूदा एपीआई वर्शन 8 एपीआई
    इवेंट लोड करना GADInterstitialDelegate या GADRewardedAdDelegate GAMInterstitialAdLoadCompletionHandler या GADRewardedAdLoadCompletionHandler
    प्रज़ेंटेशन इवेंट GADFullScreenContentDelegate

    पहले, किसी विज्ञापन इवेंट को सुनने के लिए, आपको ऐसी क्लास रजिस्टर करनी होगी जो पेज पर अचानक दिखने वाले विज्ञापन की डेलिगेट प्रॉपर्टी में GADInterstitialDelegate प्रोटोकॉल लागू करती हो. इसके अलावा, ऐसी क्लास को रजिस्टर किया जाता था जो इनाम वाले विज्ञापन की डेलिगेट प्रॉपर्टी पर प्रोटोकॉल लागू करती हो. यह इस बात पर निर्भर करता है कि कौनसा फ़ॉर्मैट इस्तेमाल किया जा रहा है.GADRewardedAdDelegate इसी प्रतिनिधि के पास किसी विज्ञापन के लोड होने और प्रज़ेंट करने की लाइफ़ साइकल से जुड़े तरीके थे.

    वर्शन 8 के साथ, लोड और प्रज़ेंटेशन इवेंट अलग-अलग होते हैं. अब विज्ञापन दिखाने से पहले, GADFullScreenContentDelegate को किसी भी समय रजिस्टर किया जा सकता है. विज्ञापन लोड करने से पहले, आपको सिर्फ़ एक प्रतिनिधि सेट करना होगा. विज्ञापन लोड इवेंट, हर फ़ॉर्मैट के लिए खास होते हैं, इसलिए उन्हें लोड करने के तरीके में पास किए गए एक ही लोड पूरा होने वाले हैंडलर पर ले जाया जाता है.

मध्यवर्ती

विज्ञापन लोड करें

नीचे दिए गए कोड स्निपेट दिखाते हैं कि पेज पर अचानक दिखने वाले विज्ञापन को कैसे लोड करें. साथ ही, विज्ञापन के सफल या लोड न होने पर इवेंट कैसे सुनें.

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;
  }];
}

Display Network में दिखने वाला विज्ञापन

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");
  }
}

प्रज़ेंटेशन विज्ञापन इवेंट

नीचे दिए गए कोड स्निपेट में बताया गया है कि विज्ञापन कब दिखता (सही या असफल) और कब खारिज हो, इसके लिए कॉलबैक को कैसे मैनेज किया जाए.

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;
}

डिसप्ले विज्ञापन और इनाम हैंडल करें

इनाम वाले विज्ञापनों के लिए, उपयोगकर्ता को इनाम मिलने पर इवेंट को मैनेज करना ज़रूरी होता है. GADRewardedAd एपीआई के वर्शन 7 में, 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");
  }
}

प्रज़ेंटेशन विज्ञापन इवेंट

GADRewardedAd एपीआई की मदद से, विज्ञापन दिखाने वाले तरीके को GADRewardedAdDelegate पास किया जाता है. GADRewardedAd एपीआई की मदद से, विज्ञापन प्रज़ेंट करने से पहले 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.");
}

लेगसी GADRewardedbaseVideoAd API को हटाना

नए GADRewardedAd एपीआई को पहली बार मार्च 2019 में लॉन्च किया गया था. यह 18 महीने से भी ज़्यादा समय से पसंदीदा एपीआई रहा है. इसमें लेगसी GADRewardedBasedVideoAd एपीआई के मुकाबले, इसमें बेहतर सुविधाएं जोड़ी गई हैं. इसमें, इनाम वाले एक से ज़्यादा विज्ञापनों को एक साथ लोड करना शामिल है.

SDK टूल के वर्शन 8.0.0 से, GADRewardedBasedVideoAd API के लेगसी वर्शन को हटा दिया गया है.

अडैप्टिव बैनर के लिए स्मार्ट बैनर का इस्तेमाल नहीं किया जा सकता

स्मार्ट बैनर विज्ञापनों की जगह, अडैप्टिव बैनर विज्ञापनों की जगह अब काम किया जाता है. अडैप्टिव बैनर की मदद से, विज्ञापन की चौड़ाई बेहतर तरीके से सेट की जा सकती है. अगर आपको पूरी चौड़ाई वाले बैनर का इस्तेमाल जारी रखना है, तो अडैप्टिव बैनर का इस्तेमाल करके भी ऐसा किया जा सकता है, जैसा कि इस कोड स्निपेट में दिखाया गया है:

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

ऐप्लिकेशन कॉलबैक को हटाना छोड़ें

सभी विज्ञापन फ़ॉर्मैट के लिए willLeaveApplication कॉलबैक को applicationDidEnterBackground: और sceneDidEnterBackground: तरीके को ध्यान में रखकर हटाया गया है. ओएस-लेवल एपीआई का इस्तेमाल करने से, उपयोगकर्ता जब भी आपका ऐप्लिकेशन छोड़कर जाते हैं, तो आपको इसकी सूचना मिलती है. इससे कोई फ़र्क़ नहीं पड़ता कि ऐसा विज्ञापन इंटरैक्शन की वजह से हुआ है या नहीं.

ध्यान दें कि willLeaveApplication कॉलबैक को कभी भी विज्ञापन क्लिक हैंडलर नहीं बनाया गया था. साथ ही, रिपोर्ट क्लिक के लिए इस कॉलबैक पर भरोसा करने से सटीक मेट्रिक नहीं बनी. उदाहरण के लिए, बाहरी ब्राउज़र लॉन्च करने वाले AdChoices आइकॉन पर क्लिक ने कॉलबैक का अनुरोध किया, लेकिन उसे एक क्लिक के तौर पर नहीं गिना.

क्लास के नाम बदले जा रहे हैं

नीचे दी गई टेबल में उन क्लास के नाम की सूची दी गई है जिन्हें वर्शन 8 में बदल दिया गया है या हटा दिया गया है. सारांश में:

  • GADUnifiedNativeAd से जुड़ी सभी क्लास का नाम बदलकर GADNativeAd कर दिया गया है.
  • GADRewardBasedVideoAd, GADNativeExpressAdView, और GADInstreamAd को हटा दिया गया है.
  • DFP प्रीफ़िक्स वाली सभी क्लास को GAM प्रीफ़िक्स से बदल दिया गया है.
v7.68.0 क्लास v8.0.0 क्लास
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial GAM पेज पर अचानक दिखने वाला विज्ञापन
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
GADUnifiedNativeAd GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomटेंप्लेटविज्ञापन GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase हटाई गई
GADInterstitial GADअचानक दिखने वाला विज्ञापन
GADNativeExpressAdView हटाई गई
GADइनाम आधारितवीडियो विज्ञापन हटाई गई
GADइनस्ट्रीम विज्ञापन हटाई गई
GADInstreamAdView हटाई गई

तरीके हटाए गए/बदले गए

नीचे दी गई टेबल में, वर्शन 8 में हुए खास बदलावों की सूची दी गई है. सारांश में:

  • पहले काम न करने वाले तरीकों और प्रॉपर्टी को हटा दिया गया है.
  • सभी फ़ॉर्मैट के लिए, ऐक्सेस देने का -willLeaveApplication: तरीका हटा दिया गया है.
  • विज्ञापन नेटवर्क कंपनी की क्लास का नाम, GADResponseInfo प्रॉपर्टी में बदल गया है.
  • टेस्ट डिवाइस आइडेंटिफ़ायर को GADRequestConfiguration प्रॉपर्टी में ले जाया गया है.
v7.68.0 क्लास v7.68.0 एपीआई v8.0.0 एपीआई ज़रूरी जानकारी
GADMobileविज्ञापन +configWithApplicationID: -startWithcompleteHandler: ऐप्लिकेशन आईडी अब Info.plist में सेट हो गई है.
+disableAutomatedInAppखरीदारी की रिपोर्टिंग -disableAutomatedInAppखरीदारी की रिपोर्टिंग
+बंद करेंSDKCrashReporting -disableSDKCrashReporting ऐप्लिकेशन को बंद करता है
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers testDeviceIdentifiers प्रॉपर्टी सभी विज्ञापन अनुरोधों पर लागू होती है, जबकि पुरानी testDevice प्रॉपर्टी को हर अनुरोध के हिसाब से सेट की गई थी.
gender हटाई गई
जन्मदिन हटाई गई
+sdkVersion GADMobileAds.shared लाइट.sdkVersion
-setBirthdayWithMonth:day:year: हटाई गई
-setLocationWithDescription: -setLocationWithLatitude:longitude:accuracy:
-tagForChildDirectedTreatment: [GADMobileAds.sharedइंस्टेंस.requestConfiguration टैगForChildDirectedTreatment]
GADErrorCode kGADगड़बड़ी* GADगड़बड़ी* k प्रीफ़िक्स को सभी गड़बड़ी कोड कॉन्स्टेंट से हटा दिया गया है.
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate हटाई गई
mediatedAdView हटाई गई
adNetworkClassName responseInfo.adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSize:
DFPBannerViewOptions -adSize छुट्टियों के पेज का इस्तेमाल करना हटाई गई
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewViewSelectScreen: -बैनरViewViewDisplayScreen:
-adViewविलखारिजस्क्रीन: -बैनरViewViewViewScreen:
-adViewDidखारिज स्क्रीन: -bannerViewDidखारिजस्क्रीन:
-adViewViewViewApplication: हटाई गई
GADNativeCustomटेंप्लेटविज्ञापन templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performanceClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediasideRatio
GADInterstitial inAppPurchaseDelegate हटाई गई
isReady हटाई गई इसके बजाय, canpresentFromRootViewController:error: का इस्तेमाल करें.
hasBeenUsed हटाई गई
-init -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialwillछोड़ेंApplication: हटाई गई
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName