Khi quảng cáo không tải được, hệ thống luôn
phương thức đại biểu hoặc trình xử lý hoàn thành
. Lệnh gọi lại này cung cấp đối tượng
GADRequestError
.
Đối với a GADBannerView
, lệnh gọi lại là:
Swift
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError)
Objective-C
- (void)adView:(nonnull GADBannerView *)bannerView didFailToReceiveAdWithError:(nonnull GADRequestError *)error;
Dưới đây là một đoạn mã minh họa thông tin có sẵn khi quảng cáo không tải được:
Swift
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) { // 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.userInfo[GADErrorUserInfoKeyResponseInfo] as? GADResponseInfo // Gets the underlyingError, if available. let underlyingError = error.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)adView:(GADBannerView *)adView didFailToReceiveAdWithError:(GADRequestError *)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); }
Thông tin này có thể được dùng để xác định chính xác hơn nguyên nhân khiến quảng cáo
không tải được.
Cụ thể, đối với các lỗi trong miền
kGADErrorDomain
, localizedDescription
có thể được tìm thấy trong bài viết này
trong trung tâm trợ giúp cùng với nội dung giải thích
chi tiết hơn và các hành động có thể thực hiện để giải quyết
vấn đề.