
프리빌드 했을 때도 상단 배너광고는 나오고 전면광고는 안 나왔는데, 프리빌드에서는 안 나올 수 도 있으니 일단 빌드해보라고 하셔서 빌드해서 올렸는데요~ 여전히 상단 배너광고는 나오고 있는데 전면광고가 안 나오고 있어요~ ;
Adcard.js
// __DEV__ 모드 일 경우에만 광고가 작동하고, 아닐경우에 코드가 있으면 로컬에서 expo start 시에 에러남, 광고용 Card 컴포넌트(adcard.js)를 만들어야됨
import React,{useEffect} from 'react';
import {View, Image, Text, StyleSheet,TouchableOpacity} from 'react-native'
import { useInterstitialAd, TestIds } from 'react-native-google-mobile-ads';
//MainPage로 부터 navigation 속성을 전달받아 Card 컴포넌트 안에서 사용
const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-6972692989047955/5262198562';//전면광고id
export default function AdCard({content,navigation}){
const { isLoaded, isClosed, load, show } = useInterstitialAd(adUnitId, {
requestNonPersonalizedAdsOnly: true,
});
useEffect(() => {
// Start loading the interstitial straight away카드에 광고를 미리 준비해놓음
load();
}, [load]);
useEffect(() => {
if (isClosed) {
// Action after the ad is closed광고가끝나거나 광고를 끄면 디테일페이지로 이동
navigation.navigate('DetailPage',{idx:content.idx})
}
}, [isClosed, navigation]);
return(
//카드 자체가 버튼역할로써 누르게되면 상세페이지로 넘어가게끔 TouchableOpacity를 사용
<TouchableOpacity style={styles.card} onPress={() => {
if (isLoaded) {
show();
} else {
// No advert ready to show yet
navigation.navigate('DetailPage',{idx:content.idx})
}
}}>
<Image style={styles.cardImage} source={{uri:content.image}}/>
<View style={styles.cardText}>
<Text style={styles.cardTitle} numberOfLines={1}>{content.title}</Text>
<Text style={styles.cardDesc} numberOfLines={3}>{content.desc}</Text>
<Text style={styles.cardDate}>{content.date}</Text>
</View>
</TouchableOpacity>
)
}
const styles = StyleSheet.create({
card:{
flex:1,
flexDirection:"row",
margin:10,
borderBottomWidth:0.5,
borderBottomColor:"#eee",
paddingBottom:10
},
cardImage: {
flex:1,
width:100,
height:100,
borderRadius:10,
},
cardText: {
flex:2,
flexDirection:"column",
marginLeft:10,
},
cardTitle: {
fontSize:20,
fontWeight:"700"
},
cardDesc: {
fontSize:15
},
cardDate: {
fontSize:10,
color:"#A6A6A6",
}
});
