React Native 전면 광고
전체 화면을 덮는 형태의 광고입니다. 화면 전환 시점이나 자연스러운 전환 포인트에서 표시합니다.
시작하기 전에
1
2
사용 방법
1. Hook 방식
import React from 'react';
import { View, Button } from 'react-native';
import { useAdropInterstitialAd } from 'adrop-ads-react-native';
const InterstitialExample = () => {
const {
load,
show,
reset,
isLoaded,
isReady,
errorCode,
} = useAdropInterstitialAd('YOUR_UNIT_ID');
const handleLoad = () => {
if (isReady) {
load();
}
};
return (
<View>
<Button title="광고 로드" onPress={handleLoad} />
<Button
title="광고 표시"
onPress={show}
disabled={!isLoaded}
/>
<Button title="리셋" onPress={reset} />
</View>
);
};hook 반환값
속성
타입
설명
2. Class 방식
import React, { useEffect, useState, useMemo } from 'react';
import { View, Button } from 'react-native';
import { AdropInterstitialAd, type AdropListener } from 'adrop-ads-react-native';
const InterstitialClassExample = () => {
const [interstitialAd, setInterstitialAd] = useState<AdropInterstitialAd>();
const [isLoaded, setIsLoaded] = useState(false);
const listener: AdropListener = useMemo(() => ({
onAdReceived: (ad) => {
console.log('광고 로드됨:', ad.unitId);
setIsLoaded(true);
},
onAdFailedToReceive: (ad, errorCode) => {
console.log('광고 로드 실패:', errorCode);
},
onAdDidPresentFullScreen: (ad) => {
console.log('광고 표시됨');
},
onAdDidDismissFullScreen: (ad) => {
console.log('광고 닫힘');
},
onAdClicked: (ad) => {
console.log('광고 클릭됨');
},
}), []);
useEffect(() => {
const ad = new AdropInterstitialAd('YOUR_UNIT_ID');
ad.listener = listener;
setInterstitialAd(ad);
return () => {
ad.destroy();
};
}, [listener]);
const handleLoad = () => interstitialAd?.load();
const handleShow = () => interstitialAd?.show();
return (
<View>
<Button title="광고 로드" onPress={handleLoad} />
<Button title="광고 표시" onPress={handleShow} disabled={!isLoaded} />
</View>
);
};AdropInterstitialAd 클래스
Parameter
Type
Description
AdropListener 인터페이스
type AdropListener = {
onAdReceived?: (ad: AdropAd) => void; // 광고 로드 성공
onAdClicked?: (ad: AdropAd) => void; // 광고 클릭
onAdImpression?: (ad: AdropAd) => void; // 광고 화면 노출
onAdFailedToReceive?: (ad: AdropAd, errorCode?: string) => void; // 광고 로드 실패
onAdDidPresentFullScreen?: (ad: AdropAd) => void; // 광고 전면 노출
onAdWillPresentFullScreen?: (ad: AdropAd) => void; // 광고 전면 노출 예정 (iOS only)
onAdDidDismissFullScreen?: (ad: AdropAd) => void; // 광고 닫힘
onAdWillDismissFullScreen?: (ad: AdropAd) => void; // 광고 닫힘 예정 (iOS only)
onAdFailedToShowFullScreen?: (ad: AdropAd, errorCode?: string) => void; // 광고 전면 노출 실패
};광고 로드 및 표시 흐름
1. useAdropInterstitialAd(unitId) 또는 new AdropInterstitialAd(unitId)
↓
2. isReady === true 확인
↓
3. load() 호출
↓
4. onAdReceived 콜백 또는 isLoaded === true
↓
5. show() 호출
↓
6. onAdDidPresentFullScreen 콜백 또는 isOpened === true
↓
7. 사용자가 광고 닫음
↓
8. onAdDidDismissFullScreen 콜백 또는 isClosed === true
↓
9. 새 광고 필요시 reset() 호출 후 2번부터 반복주의 사항
Last updated