import React, { useEffect } from 'react';
import { Platform, SafeAreaView, ScrollView, StyleSheet, Text, View, Button } from 'react-native';
import {
AdPopcornSSP,
AdPopcornInterstitialAd,
AdPopcornSSPEvents,
AdPopcornInterstitialAdEvents,
} from 'react-native-adpopcorn-ssp';
const APP_KEY_ANDROID = '663451319';
const APP_KEY_IOS = '397261446';
function App(): JSX.Element {
useEffect(() => {
// SSP 초기화 이벤트
const initSub = AdPopcornSSP.addListener(AdPopcornSSPEvents.OnAdPopcornSSPSDKDidInitialize, () => {
console.log('[SSP] SDK Initialized');
if (Platform.OS === 'ios') {
AdPopcornInterstitialAd.createInstance(APP_KEY_IOS, 'iOS_INTERSTITIAL');
} else {
AdPopcornInterstitialAd.createInstance(APP_KEY_ANDROID, 'INTERSTITIAL');
}
});
// Interstitial 이벤트
const intLoadedSub = AdPopcornInterstitialAd.addListener(AdPopcornInterstitialAdEvents.OnInterstitialLoaded, (e) => console.log('[Interstitial] Loaded:', e.placementId));
const intFailedSub = AdPopcornInterstitialAd.addListener(AdPopcornInterstitialAdEvents.OnInterstitialReceiveFailed, (e) => console.log('[Interstitial] LoadFailed:', e.placementId, e.errorCode, e.errorMessage));
const intOpenedSub = AdPopcornInterstitialAd.addListener(AdPopcornInterstitialAdEvents.OnInterstitialOpened, (e) => console.log('[Interstitial] Opened:', e.placementId));
const intOpenFailSub = AdPopcornInterstitialAd.addListener(AdPopcornInterstitialAdEvents.OnInterstitialOpenFailed, (e) => console.log('[Interstitial] OpenFailed:', e.placementId, e.errorCode));
const intClosedSub = AdPopcornInterstitialAd.addListener(AdPopcornInterstitialAdEvents.OnInterstitialClosed, (e) => console.log('[Interstitial] Closed:', e.placementId));
const intClickedSub = AdPopcornInterstitialAd.addListener(AdPopcornInterstitialAdEvents.OnInterstitialClicked, (e) => console.log('[Interstitial] Clicked:', e.placementId));
// SDK 초기화
const appKey = Platform.OS === 'ios' ? APP_KEY_IOS : APP_KEY_ANDROID;
AdPopcornSSP.init(appKey);
return () => {
initSub.remove();
intLoadedSub.remove();
intFailedSub.remove();
intOpenedSub.remove();
intOpenFailSub.remove();
intClosedSub.remove();
intClickedSub.remove();
};
}, []);
const loadInterstitial = () => {
const pid = Platform.OS === 'ios' ? 'iOS_INTERSTITIAL' : 'INTERSTITIAL';
AdPopcornInterstitialAd.loadAd(pid);
};
const showInterstitial = () => {
const pid = Platform.OS === 'ios' ? 'iOS_INTERSTITIAL' : 'INTERSTITIAL';
AdPopcornInterstitialAd.showAd(pid);
};
return (
<SafeAreaView style={styles.container}>
<ScrollView contentInsetAdjustmentBehavior="automatic" contentContainerStyle={{ paddingBottom: 100 }}>
<Text style={styles.title}>AdPopcorn SSP Example</Text>
<View style={styles.section}>
<Text style={styles.sectionTitle}>Interstitial</Text>
<Button title="Load Interstitial" onPress={loadInterstitial} />
<Button title="Show Interstitial" onPress={showInterstitial} />
</View>
</ScrollView>
</SafeAreaView>
);
}