廣告載入錯誤
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
廣告載入失敗時,SDK 會呼叫委派方法或完成處理常式,並提供 NSError
物件。
以 GAMBannerView
為例,SDK 會呼叫以下方法:
以下範例顯示了廣告載入失敗時可取得的資訊:
Swift
func bannerView(_ bannerView: AdManagerBannerView, 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? ResponseInfo
// 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:(GAMBannerView *)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);
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-02 (世界標準時間)。
[null,null,["上次更新時間:2025-09-02 (世界標準時間)。"],[[["\u003cp\u003eWhen Google Mobile Ads SDK fails to load an ad, a delegate method or completion handler is called, providing an \u003ccode\u003eNSError\u003c/code\u003e object containing details about the failure.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eNSError\u003c/code\u003e object provides access to the error domain, code, message, underlying error, and response information via its properties and user info dictionary.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize this information to diagnose and address the root cause of ad load failures, ensuring a smoother ad experience.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets illustrate how to access and interpret the error information within the delegate methods for \u003ccode\u003eGAMBannerView\u003c/code\u003e.\u003c/p\u003e\n"]]],["When an ad fails to load, a delegate method (`bannerView:didFailToReceiveAdWithError:`) is triggered, providing an `NSError` object. This object contains the error's domain, code, and a descriptive message. It also offers `responseInfo` for request details and `underlyingError` if available. Developers can retrieve and utilize this error information in both Swift and Objective-C, allowing for error handling and debugging.\n"],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/ad-load-errors \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/ad-load-errors \"View this page for the iOS platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/unity/ad-load-errors \"View this page for the Unity platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/ad-load-errors \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nIn cases where an ad fails to load, a\ndelegate method or completion handler\nis called which provides a `NSError` object.\n\nFor `GAMBannerView`, the following is called: \n\nSwift \n\n func bannerView(_ bannerView: AdManagerBannerView, /ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADBannerViewDelegate#-adview:didfailtoreceiveadwitherror: error: Error)\n\nObjective-C \n\n - (void)bannerView:(nonnull GAMBannerView *)bannerView\n /ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADBannerViewDelegate#-adview:didfailtoreceiveadwitherror:error;\n\nThe following example shows the information available when an ad fails to load: \n\nSwift \n\n func bannerView(_ bannerView: AdManagerBannerView, didFailToReceiveAdWithError error: Error) {\n // Gets the domain from which the error came.\n let errorDomain = error.domain\n // Gets the error code. See\n // https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Enums/GADErrorCode\n // for a list of possible codes.\n let errorCode = error.code\n // Gets an error message.\n let errorMessage = error.localizedDescription\n // Gets additional response information about the request. See\n // https://developers.google.com/ad-manager/mobile-ads-sdk/ios/response-info for more information.\n let responseInfo = (error as NSError).userInfo[GADErrorUserInfoKeyResponseInfo] as? ResponseInfo\n // Gets the underlyingError, if available.\n let underlyingError = (error as NSError).userInfo[NSUnderlyingErrorKey] as? Error\n if let responseInfo = responseInfo {\n print(\"Received error with domain: \\(errorDomain), code: \\(errorCode),\"\n + \"message: \\(errorMessage), responseInfo: \\(responseInfo),\"\n + \"underlyingError: \\(underlyingError?.localizedDescription ?? \"nil\")\")\n }\n }\n\nObjective-C \n\n - (void)bannerView:(GAMBannerView *)bannerView\n didFailToReceiveAdWithError:(NSError *)error {\n // Gets the domain from which the error came.\n NSString *errorDomain = error.domain;\n // Gets the error code. See\n // https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Enums/GADErrorCode\n // for a list of possible codes.\n int errorCode = error.code;\n // Gets an error message.\n NSString *errorMessage = error.localizedDescription;\n // Gets additional response information about the request. See\n // https://developers.google.com/ad-manager/mobile-ads-sdk/ios/response-info for more\n // information.\n GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo];\n // Gets the underlyingError, if available.\n NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey];\n NSLog(@\"Received error with domain: %@, code: %ld, message: %@, \"\n @\"responseInfo: %@, underlyingError: %@\",\n errorDomain, errorCode, errorMessage, responseInfo,\n underlyingError.localizedDescription);\n }"]]