firebase::admob::rewarded_video

Loads and displays rewarded video ads via AdMob mediation.

Summary

The rewarded_video namespace contains methods to load and display rewarded video ads via the Google Mobile Ads SDK. The underlying SDK objects for rewarded video on Android and iOS are singletons, so there are no objects to represent individual ads here. Instead, methods in the rewarded_video namespace are invoked to initialize, load, and show.

The basic steps for loading and displaying an ad are:

  1. Call Initialize to init the library and mediation adapters.
  2. Call LoadAd to load an ad (some SDKs may have cached an ad at init time).
  3. Call Show to show the ad to the user.
  4. Repeat steps 2 and 3 as desired.
  5. Call Destroy when your app is completely finished showing rewarded video ads.

Note that Initialize must be the very first thing called, and Destroy must be the very last.

The library maintains a presentation state that indicates whether or not an ad is currently onscreen, but otherwise provides information about its current state through Futures. Initialize, LoadAd, and so on each have a corresponding Future from which apps can determine the result of the previous call.

In addition, applications can create their own subclasses of Listener, pass an instance to the SetListener method, and receive callbacks whenever the presentation state changes or an ad has been viewed in full and the user is due a reward.

Here's how one might initialize, load, and show a rewarded video ad while checking against the result of the previous action at each step:

firebase::admob::rewarded_video::Initialize();

Then, later:

if (firebase::admob::rewarded_video::InitializeLastResult().status() ==
    firebase::kFutureStatusComplete &&
    firebase::admob::rewarded_video::InitializeLastResult().error() ==
    firebase::admob::kAdMobErrorNone) {
  firebase::admob::rewarded_video::LoadAd(my_ad_unit_str, my_ad_request);
}

And after that:

if (firebase::admob::rewarded_video::LoadAdLastResult().status() ==
    firebase::kFutureStatusComplete &&
    firebase::admob::rewarded_video::LoadAdLastResult().error() ==
    firebase::admob::kAdMobErrorNone) {
  firebase::admob::rewarded_video::Show(my_ad_parent);
}

Enumerations

PresentationState{
  kPresentationStateHidden = 0,
  kPresentationStateCoveringUI,
  kPresentationStateVideoHasStarted
}
enum
The possible presentation states for rewarded video.

Functions

Destroy()
void
Cleans up and deallocates any resources used by rewarded video.
GetPresentationState()
FIREBASE_DEPRECATED PresentationState
Deprecated. Renamed to presentation_state().
Returns the current presentation state, indicating if an ad is visible or if a video has started playing.
Initialize()
Future< void >
Initializes rewarded video.
InitializeLastResult()
Future< void >
Returns a Future that has the status of the last call to Initialize.
LoadAd(const char *ad_unit_id, const AdRequest & request)
Future< void >
Begins an asynchronous request for an ad.
LoadAdLastResult()
Future< void >
Returns a Future containing the status of the last call to LoadAd.
Pause()
Future< void >
Pauses any background processing associated with rewarded video.
PauseLastResult()
Future< void >
Returns a Future containing the status of the last call to Pause.
Resume()
Future< void >
Resumes the rewarded video system after pausing.
ResumeLastResult()
Future< void >
Returns a Future containing the status of the last call to Resume.
SetListener(Listener *listener)
void
Sets the Listener that should receive callbacks.
Show(AdParent parent)
Future< void >
Shows an ad, assuming one has loaded.
ShowLastResult()
Future< void >
Returns a Future containing the status of the last call to Show.
presentation_state()
Returns the current presentation state, indicating if an ad is visible or if a video has started playing.

Classes

firebase::admob::rewarded_video::Listener

A listener class that developers can extend and pass to SetListener to be notified of rewards and changes to the presentation state.

firebase::admob::rewarded_video::PollableRewardListener

A polling-based listener that developers can instantiate and pass to SetListener in order to queue rewards for later retrieval.

Structs

firebase::admob::rewarded_video::RewardItem

A reward to be given to the user in exchange for watching a rewarded video ad.

Enumerations

PresentationState

 PresentationState

The possible presentation states for rewarded video.

Properties
kPresentationStateCoveringUI

A rewarded video ad is completely covering the screen or has caused focus to leave the application (for example, when opening an external browser during a clickthrough), but the video associated with the ad has yet to begin playing.

kPresentationStateHidden

No ad is currently being shown.

kPresentationStateVideoHasStarted

All of the above conditions are true except that the video associated with the ad began playing at some point in the past.

Functions

Destroy

void Destroy()

Cleans up and deallocates any resources used by rewarded video.

No other methods in rewarded_video should be called once this method has been invoked. The system is closed for business at that point.

GetPresentationState

FIREBASE_DEPRECATED PresentationState GetPresentationState()

Returns the current presentation state, indicating if an ad is visible or if a video has started playing.

Deprecated. Renamed to presentation_state().

Details
Returns
The current presentation state.

Initialize

Future< void > Initialize()

Initializes rewarded video.

This must be the first method invoked in this namespace.

InitializeLastResult

Future< void > InitializeLastResult()

Returns a Future that has the status of the last call to Initialize.

LoadAd

Future< void > LoadAd(
  const char *ad_unit_id,
  const AdRequest & request
)

Begins an asynchronous request for an ad.

Details
Parameters
ad_unit_id
The ad unit ID to use in the request.
request
An AdRequest struct with information about the request to be made (such as targeting info).

LoadAdLastResult

Future< void > LoadAdLastResult()

Returns a Future containing the status of the last call to LoadAd.

Pause

Future< void > Pause()

Pauses any background processing associated with rewarded video.

Should be called whenever the C++ engine pauses or the application loses focus.

PauseLastResult

Future< void > PauseLastResult()

Returns a Future containing the status of the last call to Pause.

Resume

Future< void > Resume()

Resumes the rewarded video system after pausing.

ResumeLastResult

Future< void > ResumeLastResult()

Returns a Future containing the status of the last call to Resume.

SetListener

void SetListener(
  Listener *listener
)

Sets the Listener that should receive callbacks.

Details
Parameters
listener
A valid Listener.

Show

Future< void > Show(
  AdParent parent
)

Shows an ad, assuming one has loaded.

LoadAd must be called before this method.

Details
Parameters
parent
An AdParent that is a reference to an iOS UIView or an Android Activity.

ShowLastResult

Future< void > ShowLastResult()

Returns a Future containing the status of the last call to Show.

presentation_state

PresentationState presentation_state()

Returns the current presentation state, indicating if an ad is visible or if a video has started playing.

Details
Returns
The current presentation state.

Send feedback about...

Need help? Visit our support page.