AdResult 物件提供偵測廣告載入失敗嘗試的機制。如果發生失敗,AdResult 方法 is_successful() 會傳回 false。
在這些情況下,呼叫 AdResult 方法 ad_error() 會傳回 AdError 物件,其中包含與錯誤相關的資訊。
以下程式碼片段說明廣告無法載入時可參閱的資訊:
firebase::Future<firebase::gma::AdResult> load_ad_future =
ad_view->LoadAd(request);
// In a game loop, monitor the load ad status
if (load_ad_future.status() == firebase::kFutureStatusComplete) {
const firebase::gma::AdResult* ad_result = load_ad_future.result();
if (!ad_result.is_successful()) {
// There was an error loading the ad.
const AdError& ad_error = ad_result.ad_error();
firebase::gma::AdErrorCode code = ad_error.code();
std::string domain = ad_error.domain();
std::string message = ad_error.message();
const firebase::gma::ResponseInfo response_info = ad_error.response_info();
printf("Received error with domain: %s, code: %d, message: %s and response info: %s\n”,
domain.c_str(), message.c_str(), response_info.ToString().c_str());
}
}
這項資訊有助您更準確地判斷廣告載入失敗的原因。特別是當錯誤來自 iOS 的 com.google.admob 網域或 Android 的 com.google.android.gms.ads 網域時,您可以在這篇說明中心文章中查詢訊息,查看更詳細的說明和可能的解決方法。