廣告無法載入時,系統會呼叫提供 LoadAdError
物件的失敗回呼。
獎勵廣告無法載入時,以下程式碼片段會擷取錯誤資訊:
onAdFailedToLoad: (ad, loadAdError) {
// Gets the domain from which the error came.
String domain = loadAdError.domain;
// Gets the error code. See
// https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/AdRequest
// and https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Enums/GADErrorCode
// for a list of possible codes.
int code = loadAdError.code;
// A log friendly string summarizing the error.
String message = loadAdError.message;
// Get response information, which may include results of mediation requests.
ResponseInfo? responseInfo = loadAdError.responseInfo;
}
這些資訊能幫助您更準確判斷廣告載入失敗的原因,尤其是網域 com.google.admob
(iOS) 或 com.google.android.gms.ads
(Android) 下的錯誤,您可以在這篇說明中心文章中查詢 GetMessage()
,瞭解更詳細的說明和可能的解決方法。