// my_ad_parent is a jobject reference to an Android Activity or// a pointer to an iOS UIView.firebase::gma::AdParentad_parent=static_cast<firebase::gma::AdParent>(my_ad_parent);firebase::Future<void>result=rewarded_ad->Initialize(ad_parent);
// Monitor the status of the future in your game loop:firebase::Future<void>result=rewarded_ad->InitializeLastResult();if(result.status()==firebase::kFutureStatusComplete){// Initialization completed.if(future.error()==firebase::gma::kAdErrorCodeNone){// Initialization successful.}else{// An error has occurred.}}else{// Initialization on-going.}
classExampleFullScreenContentListener:publicfirebase::gma::FullScreenContentListener{public:ExampleFullScreenContentListener(){}voidOnAdClicked()override{// This method is invoked when the user clicks the ad.}voidOnAdDismissedFullScreenContent()override{// This method is invoked when the ad dismisses full screen content.}voidOnAdFailedToShowFullScreenContent(constAdError&error)override{// This method is invoked when the ad failed to show full screen content.// Details about the error are contained within the AdError parameter.}voidOnAdImpression()override{// This method is invoked when an impression is recorded for an ad.}voidOnAdShowedFullScreenContent()override{// This method is invoked when the ad showed its full screen content.}};ExampleFullScreenContentListener*example_full_screen_content_listener=newExampleFullScreenContentListener();rewarded_ad->SetFullScreenContentListener(example_full_screen_content_listener);
// A simple listener track UserEarnedReward events.classExampleUserEarnedRewardListener:publicfirebase::gma::UserEarnedRewardListener{public:ExampleUserEarnedRewardListener(){}voidOnUserEarnedReward(constfirebase::gma::AdReward&reward)override{// Reward the user!}};ExampleUserEarnedRewardListener*user_earned_reward_listener=newExampleUserEarnedRewardListener();firebase::Future<void>result=rewarded_ad->Show(user_earned_reward_listener);
よくある質問
初期化の呼び出しでタイムアウトは発生しますか?
メディエーション ネットワークの初期化が完了していなくても、Google Mobile Ads C++ SDK では 10 秒が経過すると Initialize() から返された firebase::Future が完了します。
SDK の初期化が完了してから広告を読み込むことが推奨されています。メディエーション ネットワークの対応準備が完了していなくても、Google Mobile Ads C++ SDK はそのネットワークに対して広告を要求します。そのため、いったんタイムアウトされても、その後に初期化が完了すれば、メディエーション ネットワークはそのセッション中に発生する後続の広告リクエストに対応することができます。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-06 UTC。"],[[["\u003cp\u003eThe Google Mobile Ads C++ SDK is deprecated and will be end-of-maintenance on June 17, 2025, with iOS and Android SDKs recommended as alternatives.\u003c/p\u003e\n"],["\u003cp\u003eRewarded ads allow users to interact with ads in exchange for in-app rewards, and this guide explains their integration using the Google Mobile Ads C++ SDK for Android and iOS.\u003c/p\u003e\n"],["\u003cp\u003eImplementation involves configuring a \u003ccode\u003eRewardedAd\u003c/code\u003e object, loading an ad, registering for callbacks using a \u003ccode\u003eFullScreenContentListener\u003c/code\u003e, and displaying the ad while handling rewards with a \u003ccode\u003eUserEarnedReward\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eTest ads should always be used during development to avoid account suspension, with dedicated test ad unit IDs provided for Android and iOS.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Mobile Ads C++ SDK initialization has a 10-second timeout, but ads can still be loaded afterward, and mediation network initialization status can be polled using \u003ccode\u003eGetInitializationStatus()\u003c/code\u003e.\u003c/p\u003e\n"]]],["The Google Mobile Ads C++ SDK is deprecated as of June 17, 2024, with support ending June 17, 2025; AdMob's iOS and Android SDKs are recommended replacements. To use rewarded ads, initialize a `RewardedAd` object, load an ad using `LoadAd()` and an `AdRequest`, and register callbacks through a `FullScreenContentListener`. When ready, show the ad via `Show()` while providing a `UserEarnedRewardListener` to handle user rewards. Remember to use test ad unit IDs during development.\n"],null,["| **DEPRECATED:** The Google Mobile Ads C++ SDK is *deprecated* as of June 17, 2024 and should not be adopted in projects that don't already use it. It will enter *End-of-Maintenance (EoM)* on June 17, 2025. Note that versions of the SDK released before the EoM date will continue to function, but no further bug fixes or changes will be released after the EoM date.\n|\n| Instead of the Google Mobile Ads C++ SDK, consider using the\n| [iOS](/admob/ios/quick-start) and\n| [Android](/admob/android/quick-start) SDKs from AdMob.\n| For support, reach out to the\n| [Google Mobile Ads SDK Technical Forum](https://groups.google.com/g/google-admob-ads-sdk).\n\n\u003cbr /\u003e\n\nRewarded ads let users have the option of interacting with them in exchange\nfor in-app rewards. This guide shows you how to integrate rewarded ads into\nAndroid and iOS apps using the Google Mobile Ads C++ SDK.\n\nRead some customer success stories:\n[case study 1](//admob.google.com/home/resources/kongregate-uses-admob-to-boost-revenue-average-30-dollar-cpm/),\n[case study 2](//admob.google.com/home/resources/four-thirty-three-uses-admob-to-boost-mobile-game-revenue-15-percent/).\n\nPrerequisites\n\n- Complete [Get started](/admob/cpp/quick-start).\n- *(Android only)* Familiarity working with JNI `jobject` references (see [Android JNI tips](//developer.android.com/training/articles/perf-jni)).\n\nAlways test with test ads\n\nWhen building and testing your apps, make sure you use test ads rather than\nlive, production ads. Failure to do so can lead to suspension of your account.\n\nThe easiest way to load test ads is to use our dedicated test ad unit ID for\nrewarded ads, which varies per device platform:\n\n- Android: `ca-app-pub-3940256099942544/5224354917`\n- iOS: `ca-app-pub-3940256099942544/1712485313`\n\nThey've been specially configured to return test ads for every request, and\nyou're free to use it in your own apps while coding, testing, and debugging.\nJust make sure you replace it with your own ad unit ID before publishing your\napp.\n\nFor more information about how the Mobile Ads SDK's test ads work, see\n[Test Ads](/admob/cpp/test-ads).\n\nImplementation\n\nThe main steps to integrate rewarded ads are:\n\n1. Load an ad.\n2. Register for callbacks.\n3. Display the ad and handle the reward event.\n\nConfigure a `RewardedAd`\n\nRewarded ads are displayed in `RewardedAd` objects, so the first step toward\nintegrating rewarded ads into your app is to create and initialize an instance\nof `RewardedAd`.\n\n1. Add the following header to your app's C++ code:\n\n ```c++\n #include \"firebase/gma/rewarded_ad.h\"\n ```\n\n \u003cbr /\u003e\n\n2. Declare and instantiate a `RewardedAd` object:\n\n ```c++\n firebase::gma::RewardedAd* rewarded_ad;\n rewarded_ad = new firebase::gma::RewardedAd();\n ```\n\n \u003cbr /\u003e\n\n3. Initialize the `RewardedAd` instance using your parent view cast to an\n `AdParent` type. The parent view is a JNI `jobject` reference to an Android\n `Activity` or a pointer to an iOS `UIView`.\n\n // my_ad_parent is a jobject reference to an Android Activity or\n // a pointer to an iOS UIView.\n firebase::gma::AdParent ad_parent =\n static_cast\u003cfirebase::gma::AdParent\u003e(my_ad_parent);\n firebase::Future\u003cvoid\u003e result = rewarded_ad-\u003eInitialize(ad_parent);\n\n4. As an alternative to retaining the future as a variable, you can periodically\n check the status of the initialization operation by invoking\n `InitializeLastResult()` on the `RewardedAd` object. This may be helpful\n for keeping track of the initialization process in your global game loop.\n\n // Monitor the status of the future in your game loop:\n firebase::Future\u003cvoid\u003e result = rewarded_ad-\u003eInitializeLastResult();\n if (result.status() == firebase::kFutureStatusComplete) {\n // Initialization completed.\n if(future.error() == firebase::gma::kAdErrorCodeNone) {\n // Initialization successful.\n } else {\n // An error has occurred.\n }\n } else {\n // Initialization on-going.\n }\n\nFor more information about working with `firebase::Future`, see\n[Use Futures to monitor the completion status of method\ncalls](/admob/cpp/quick-start#futures).\n\nLoad an ad\n\nLoading an ad is accomplished using the `LoadAd()` method on a `RewardedAd`\nobject. The load method requires that you've initialized the `RewardedAd`\nobject, and that you have your ad unit ID and an `AdRequest` object. A\n`firebase::Future` is returned which you can use to monitor the state and result\nof the load operation.\n\nThe following code shows how to load an ad once the `RewardedAd` has been\nsuccessfully initialized: \n\n firebase::gma::AdRequest ad_request;\n firebase::Future\u003cfirebase::gma::AdResult\u003e load_ad_result;\n load_ad_result = rewarded_ad-\u003eLoadAd(rewarded_ad_unit_id, ad_request);\n\nRegister for callbacks\n\nYou must extend the `FullScreenContentListener` class in order to receive\nnotifications of rewarded ad presentation and lifecycle events. Your custom\n`FullScreenContentListener` subclass can be registered through the\n`RewardedAd::SetFullScreenContentListener()` method, and it will receive\ncallbacks when the ad presents successfully or unsuccessfully as well as when\nit's dismissed.\n\nThe following code shows how to extend the class and assign it to the ad: \n\n```c++\n class ExampleFullScreenContentListener\n : public firebase::gma::FullScreenContentListener {\n\n public:\n ExampleFullScreenContentListener() {}\n\n void OnAdClicked() override {\n // This method is invoked when the user clicks the ad.\n }\n\n void OnAdDismissedFullScreenContent() override {\n // This method is invoked when the ad dismisses full screen content.\n }\n\n void OnAdFailedToShowFullScreenContent(const AdError& error) override {\n // This method is invoked when the ad failed to show full screen content.\n // Details about the error are contained within the AdError parameter.\n }\n\n void OnAdImpression() override {\n // This method is invoked when an impression is recorded for an ad.\n }\n\n void OnAdShowedFullScreenContent() override {\n // This method is invoked when the ad showed its full screen content.\n }\n };\n\n ExampleFullScreenContentListener* example_full_screen_content_listener =\n new ExampleFullScreenContentListener();\n rewarded_ad-\u003eSetFullScreenContentListener(example_full_screen_content_listener);\n```\n\n`RewardedAd` is a one-time-use object. This means that once a rewarded ad is\nshown, it cannot be shown again. A best practice is to load another rewarded ad\nin the `OnAdDismissedFullScreenContent()` method of your\n`FullScreenContentListener` so that the next rewarded ad starts loading as soon\nas the previous one is dismissed.\n\nShow the ad and handle the reward event\n\nBefore displaying a rewarded ad to users, you must present the user with an\nexplicit choice to view rewarded ad content in exchange for a reward. Rewarded\nads must always be an opt-in experience.\n\nWhen presenting your ad, you must provide a `UserEarnedReward` object to handle\nthe reward for the user.\n\nThe following code shows how to display a `RewardedAd`: \n\n // A simple listener track UserEarnedReward events.\n class ExampleUserEarnedRewardListener :\n public firebase::gma::UserEarnedRewardListener {\n public:\n ExampleUserEarnedRewardListener() { }\n\n void OnUserEarnedReward(const firebase::gma::AdReward& reward) override {\n // Reward the user!\n }\n };\n\n ExampleUserEarnedRewardListener* user_earned_reward_listener =\n new ExampleUserEarnedRewardListener();\n firebase::Future\u003cvoid\u003e result = rewarded_ad-\u003eShow(user_earned_reward_listener);\n\nFAQ\n\nIs there a timeout for the initialization call?\n: After 10 seconds, the Google Mobile Ads C++ SDK completes the\n `firebase::Future` returned by `Initialize()` even if a mediation network still\n hasn't completed initialization.\n\nWhat if some mediation networks aren't ready when I get the initialization callback?\n\n: It's a best practice to load ads after the SDK initialization has completed.\n Even if a mediation network is not ready, the Google Mobile Ads C++ SDK will\n still ask that network for an ad. So if a mediation network finishes\n initializing after the timeout, it can still service future ad requests in that\n session.\n\n: You can continue to poll the initialization status of all adapters throughout\n your app session by calling `GetInitializationStatus()`.\n\nHow do I find out why a particular mediation network isn't ready?\n\n: `AdapterStatus.description()` describes why an adapter is not ready to service\n ad requests. See the source code of our\n [example quickstart app](//github.com/firebase/quickstart-cpp/tree/main/gma/testapp)\n in GitHub for an example of logging mediation adapter status.\n\nAdditional resources\n\nExample in GitHub\n\n- View the source code of our example [quickstart app](//github.com/firebase/quickstart-cpp/tree/main/gma/testapp) in GitHub."]]