Created
June 6, 2021 05:21
-
-
Save LuffyAnshul/b9e365cd9a35d50be91ec340f673260d to your computer and use it in GitHub Desktop.
Reward ADs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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