mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Compare commits
1 Commits
fix/disabl
...
fix-admob-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3476c043f8 |
@@ -123,6 +123,20 @@ namespace gdjs {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
document.addEventListener('pause', async () => {
|
||||||
|
logger.info('App paused, hiding banner if any.');
|
||||||
|
if (banner) {
|
||||||
|
banner.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('resume', async () => {
|
||||||
|
logger.info('App resumed, showing banner again.');
|
||||||
|
if (banner) {
|
||||||
|
banner.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to know if we are on mobile and admob is correctly initialized.
|
* Helper to know if we are on mobile and admob is correctly initialized.
|
||||||
*/
|
*/
|
||||||
@@ -302,20 +316,46 @@ namespace gdjs {
|
|||||||
await hideBanner();
|
await hideBanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bannerId = localStorage.getItem('lastBannerId');
|
||||||
|
|
||||||
|
logger.info(`bannerId ${bannerId}`);
|
||||||
|
|
||||||
bannerConfigured = false;
|
bannerConfigured = false;
|
||||||
bannerLoaded = false;
|
bannerLoaded = false;
|
||||||
|
|
||||||
|
if (bannerId) {
|
||||||
|
logger.info('bannerId is set, trying to reuse it');
|
||||||
|
try {
|
||||||
|
const result = admob.BannerAd.getAdById(adUnitId);
|
||||||
|
if (result) {
|
||||||
|
logger.info('bannerId is valid, reusing it');
|
||||||
|
} else {
|
||||||
|
logger.info('result null');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.info(error);
|
||||||
|
logger.info('bannerId is invalid, not reusing it');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
banner = new admob.BannerAd({
|
banner = new admob.BannerAd({
|
||||||
adUnitId,
|
adUnitId,
|
||||||
position: atTop ? 'top' : 'bottom',
|
position: atTop ? 'top' : 'bottom',
|
||||||
size: bannerRequestedAdSizeType,
|
size: bannerRequestedAdSizeType,
|
||||||
|
id: 123,
|
||||||
});
|
});
|
||||||
|
|
||||||
banner.on('load', () => {
|
console.log(banner);
|
||||||
|
console.log(admob);
|
||||||
|
|
||||||
|
banner.on('load', (event) => {
|
||||||
|
logger.info('banner loaded', JSON.stringify(event));
|
||||||
bannerShowing = true;
|
bannerShowing = true;
|
||||||
bannerLoaded = true;
|
bannerLoaded = true;
|
||||||
|
localStorage.setItem('lastBannerId', event.adId);
|
||||||
});
|
});
|
||||||
banner.on('loadfail', () => {
|
banner.on('loadfail', (event) => {
|
||||||
|
logger.info('banner did not load properly', JSON.stringify(event));
|
||||||
bannerShowing = false;
|
bannerShowing = false;
|
||||||
bannerLoaded = false;
|
bannerLoaded = false;
|
||||||
bannerErrored = true;
|
bannerErrored = true;
|
||||||
|
Reference in New Issue
Block a user