-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameOverAdMob.js
57 lines (51 loc) · 1.83 KB
/
gameOverAdMob.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useState, useEffect } from 'react';
import { Platform, Button } from 'react-native';
import Constants from 'expo-constants';
import {
setTestDeviceIDAsync,
AdMobInterstitial,
} from 'expo-ads-admob';
export function interstitialAdSetUp() {
const gameOverAdTestID = Platform.select({
// https://developers.google.com/admob/ios/test-ads
ios: 'ca-app-pub-3940256099942544/4411468910',
// https://developers.google.com/admob/android/test-ads
android: 'ca-app-pub-3940256099942544/1033173712',
});
const gameOverAdProductionID = Platform.select({
ios: Constants.manifest.extra.gameOverAdProductionID.ios,
android: Constants.manifest.extra.gameOverAdProductionID.android,
});
// Is a real device and running in production.
const gameOverAdUnitID =
Constants.isDevice && !__DEV__ ? gameOverAdProductionID : gameOverAdTestID;
useEffect(() => {
async function setUp() {
try {
// Set global test device ID
await setTestDeviceIDAsync('EMULATOR');
// Configure ad unit
await AdMobInterstitial.setAdUnitID(gameOverAdUnitID);
// Load first add
await AdMobInterstitial.requestAdAsync({ servePersonalizedAds: false });
} catch (err) {
console.warn(err)
}
};
setUp();
return () => {
// Unsubscribe from event listeners
AdMobInterstitial.removeAllListeners();
}
}, [])
};
export async function showInterstitialAd() {
try {
// Show loaded ad
await AdMobInterstitial.showAdAsync();
// Load new ad
await AdMobInterstitial.requestAdAsync({ servePersonalizedAds: false });
} catch (err) {
console.warn(err);
}
}