광고를 로드하지 못한 경우
NSError
객체를 제공하는
대리자 메서드 또는 완료 핸들러 가 호출됩니다.
a GAMBannerView
의 경우 다음이 호출됩니다.
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/ad-manager/mobile-ads-sdk/ios/api/reference/Enums/GADErrorCode
// for a list of possible codes.
let errorCode = error.code
// Gets an error message.
let errorMessage = error.localizedDescription
// Gets additional response information about the request. See
// https://developers.google.com/ad-manager/mobile-ads-sdk/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/ad-manager/mobile-ads-sdk/ios/api/reference/Enums/GADErrorCode
// for a list of possible codes.
int errorCode = error.code;
// Gets an error message.
NSString *errorMessage = error.localizedDescription;
// Gets additional response information about the request. See
// https://developers.google.com/ad-manager/mobile-ads-sdk/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);
}
이 정보를 사용하여 광고 로드에 실패한 원인을 보다 정확하게 파악할 수 있습니다.