Skip to content

Instantly share code, notes, and snippets.

@LuffyAnshul
Created June 6, 2021 05:21
Show Gist options
  • Save LuffyAnshul/b9e365cd9a35d50be91ec340f673260d to your computer and use it in GitHub Desktop.
Save LuffyAnshul/b9e365cd9a35d50be91ec340f673260d to your computer and use it in GitHub Desktop.
Reward ADs
import { TestIds, RewardedAd, RewardedAdEventType } from '@react-native-firebase/admob';
....
showRewardAd = () => {
// Create a new instance
const rewardAd = RewardedAd.createForAdRequest(TestIds.REWARDED);
// Add event handlers
rewardAd.onAdEvent((type, error) => {
if (type === RewardedAdEventType.LOADED) {
rewardAd.show();
}
if (type === RewardedAdEventType.EARNED_REWARD) {
console.log('User earned reward of 5 lives');
Alert.alert(
'Reward Ad',
'You just earned a reward of 5 lives',
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: true }
)
}
});
// Load a new advert
rewardAd.load();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment