React Native 전면 광고
전면 광고 노출하기
// (선택사항) 이벤트 리스너 선언하기
const listener = {
onAdReceived: (ad: AdropInterstitialAd) =>
console.log(`Adrop interstitial Ad load with unitId ${ad.unitId}!`),
onAdFailedToReceive: (ad: AdropInterstitialAd, errorCode: string) =>
console.log(`error in ${ad.unitId} while load: ${errorCode}`),
onAdFailedToShowFullScreen: (ad: AdropInterstitialAd, errorCode: string) =>
console.log(`error in ${ad.unitId} while showing: ${errorCode}`),
...
}
const YourComponent: React.FC = () => {
const [interstitialAd, setInterstitialAd] = useState<AdropInterstitialAd>(null)
useEffect(() => {
let adropInterstitialAd = new AdropInterstitialAd('YOUR_UNIT_ID')
adropInterstitialAd.listener = listener
adropInterstitialAd.load()
setInterstitialAd(adropInterstitialAd)
}, []);
const show = () => {
if (interstitialAd?.isLoaded) {
interstitialAd?.show()
} else {
console.log('interstitial ad is loading...')
}
}
return (
<View>
<Button title="display ad" onPress={show}/>
</View>
)
}
const YourComponent: React.FC = () => {
const { load, show, isLoaded, reset } =
useAdropInterstitialAd('YOUR_UNIT_ID')
const handleShow = () => {
if (isLoaded) show()
}
return (
<View>
<Button title="load ad" onPress={load}/>
<Button title="display ad" onPress={handleShow}/>
</View>
)
}
전면 광고 Destroy
useEffect(() => {
return () => {
interstitialAd.destroy()
}
}, [])
useEffect(() => {
return () => {
reset()
}
}, [])
Last updated