【发布时间】:2020-06-29 20:51:00
【问题描述】:
import { InterstitialAd, AdEventType, TestIds } from '@react-native-firebase/admob';
const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy';
const interstitial = InterstitialAd.createForAdRequest(adUnitId, {
requestNonPersonalizedAdsOnly: true,
keywords: ['fashion', 'clothing'],
});
function App() {
const [loaded, setLoaded] = useState(false);
useEffect(() => {
const eventListener = interstitial.onAdEvent(type => {
if (type === AdEventType.LOADED) {
setLoaded(true);
}
});
// Start loading the interstitial straight away
interstitial.load();
// Unsubscribe from events on unmount
return () => {
eventListener();
};
}, []);
// No advert ready to show yet
if (!loaded) {
return null;
}
return (
<Button
title="Show Interstitial"
onPress={() => {
interstitial.show();
}}
/>
);
}
当我第一次点击按钮时,广告就会显示。但是当我再次点击按钮时,它会抛出一个错误。
错误:firebase.admob().InterstitialAd.show() 请求的插页式广告尚未加载,无法显示。
我该如何解决这个问题?我想在每次点击按钮时展示一个广告。
【问题讨论】:
标签: firebase react-native admob