如果廣告無法載入,系統會呼叫失敗回呼,並提供 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/android/reference/com/google/android/gms/ads/AdRequest
// and https://developers.google.com/admob/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;
}
這項資訊可用來更準確地判定廣告載入失敗的原因。請特別注意,在 iOS 的 com.google.admob
網域和 Android 的 com.google.android.gms.ads
下,訂錯的 GetMessage()
可參閱這篇說明中心文章,進一步瞭解更詳細的說明,以及可採取哪些動作來解決問題。