विज्ञापन लोड करने से जुड़ी गड़बड़ियां

जब कोई विज्ञापन लोड नहीं हो पाता, तो हमेशा डेलिगेट या पूरा करने वाले हैंडलर को कहा जाता है, जो NSError ऑब्जेक्ट देता है.

a GADBannerViewके लिए, इन्हें कॉल किया जाता है:

Swift

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error)

Objective-C

- (void)bannerView:(nonnull GADBannerView *)bannerView
    didFailToReceiveAdWithError:(nonnull NSError *)error;

यहां एक कोड स्निपेट दिया गया है, जो विज्ञापन के लोड होने में उपलब्ध जानकारी दिखाता है:

Swift

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
    // Gets the domain from which the error came.
    let errorDomain = error.domain
    // Gets the error code. See
    // https://developers.google.com/admob/ios/api/reference/Enums/GADErrorCode
    // for a list of possible codes.
    let errorCode = error.code
    // Gets an error message.
    // For example "Account not approved yet". See
    // https://support.google.com/admob/answer/9905175 for explanations of
    // common errors.
    let errorMessage = error.localizedDescription
    // Gets additional response information about the request. See
    // https://developers.google.com/admob/ios/response-info for more information.
    let responseInfo = (error as NSError).userInfo[GADErrorUserInfoKeyResponseInfo] as? GADResponseInfo
    // Gets the underlyingError, if available.
    let underlyingError = (error as NSError).userInfo[NSUnderlyingErrorKey] as? Error
    if let responseInfo = responseInfo {
        print("Received error with domain: \(errorDomain), code: \(errorCode),"
          + "message: \(errorMessage), responseInfo: \(responseInfo),"
          + "underlyingError: \(underlyingError?.localizedDescription ?? "nil")")
    }
}

Objective-C

- (void)bannerView:(GADBannerView *)bannerView
    didFailToReceiveAdWithError:(NSError *)error {
  // Gets the domain from which the error came.
  NSString *errorDomain = error.domain;
  // Gets the error code. See
  // https://developers.google.com/admob/ios/api/reference/Enums/GADErrorCode
  // for a list of possible codes.
  int errorCode = error.code;
  // Gets an error message.
  // For example "Account not approved yet". See
  // https://support.google.com/admob/answer/9905175 for explanations of
  // common errors.
  NSString *errorMessage = error.localizedDescription;
  // Gets additional response information about the request. See
  // https://developers.google.com/admob/ios/response-info for more
  // information.
  GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo];
  // Gets the underlyingError, if available.
  NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey];
  NSLog(@"Received error with domain: %@, code: %ld, message: %@, "
        @"responseInfo: %@, underlyingError: %@",
        errorDomain, errorCode, errorMessage, responseInfo,
        underlyingError.localizedDescription);
}

इस जानकारी का इस्तेमाल ज़्यादा सटीक तरीके से यह तय करने के लिए किया जा सकता है कि विज्ञापन क्यों लोड नहीं हुआ. खास तौर पर, GADErrorDomain के लिए, localizedDescription को सहायता केंद्र के इस लेख में देखा जा सकता है. यहां समस्या को हल करने के बारे में ज़्यादा जानकारी और कार्रवाई की जा सकती है.