import React, { useEffect } from 'react';
import { Platform, SafeAreaView, ScrollView, StyleSheet, Text, View, Button } from 'react-native';
import {
AdPopcornSSP,
AdPopcornRewardVideoAd,
AdPopcornSSPEvents,
AdPopcornRewardVideoAdEvents,
} 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') {
AdPopcornRewardVideoAd.createInstance(APP_KEY_IOS, 'iOS_REWARD_VIDEO');
} else {
AdPopcornRewardVideoAd.createInstance(APP_KEY_ANDROID, 'REWARD_VIDEO');
}
});
// Reward Video 이벤트
const rvLoadedSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoAdLoaded, (e) => console.log('[RewardVideo] Loaded:', e.placementId));
const rvFailedSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoAdLoadFailed, (e) => console.log('[RewardVideo] LoadFailed:', e.placementId, e.errorCode, e.errorMessage));
const rvOpenedSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoAdOpened, (e) => console.log('[RewardVideo] Opened:', e.placementId));
const rvOpenFailSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoAdOpenFalied, (e) => console.log('[RewardVideo] OpenFailed:', e.placementId));
const rvClosedSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoAdClosed, (e) => console.log('[RewardVideo] Closed:', e.placementId));
const rvClickedSub = Platform.OS === 'android' ? AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoAdClicked, (e) => console.log('[RewardVideo] Clicked:', e.placementId)) : null;
const rvCompletedSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardVideoPlayCompleted, (e) => console.log('[RewardVideo] PlayCompleted:', e.placementId));
const rvPlusSub = AdPopcornRewardVideoAd.addListener(AdPopcornRewardVideoAdEvents.OnRewardPlusCompleted, (e) => console.log('[RewardVideo] RewardPlusCompleted:', e.resultCode, e.reward));
// SDK 초기화
const appKey = Platform.OS === 'ios' ? APP_KEY_IOS : APP_KEY_ANDROID;
AdPopcornSSP.init(appKey);
AdPopcornSSP.setUserId('react-native-test-user');
return () => {
initSub.remove();
rvLoadedSub.remove();
rvFailedSub.remove();
rvOpenedSub.remove();
rvOpenFailSub.remove();
rvClosedSub.remove();
rvClickedSub?.remove();
rvCompletedSub.remove();
rvPlusSub.remove();
};
}, []);
const loadReward = () => {
const pid = Platform.OS === 'ios' ? 'iOS_REWARD_VIDEO' : 'REWARD_VIDEO';
AdPopcornRewardVideoAd.loadAd(pid);
};
const showReward = () => {
const pid = Platform.OS === 'ios' ? 'iOS_REWARD_VIDEO' : 'REWARD_VIDEO';
AdPopcornRewardVideoAd.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}>Reward Video</Text>
<Button title="Load Reward Video" onPress={loadReward} />
<Button title="Show Reward Video" onPress={showReward} />
</View>
</ScrollView>
</SafeAreaView>
);
}