1. 설치
yarn add @react-native-firebase/admob
cd ios && pod install
2. 적용
// <project-root>/firebase.json
{
"react-native": {
"admob_android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
"admob_ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
}
}
3. 실행
3-1. iOS 에러
빌드는 잘 됐는데 xcode 터미널에 이러한 에러가 떴음
Terminating app due to uncaught exception 'GADInvalidInitializationException',
reason: 'The Google Mobile Ads SDK was initialized without an application ID.
Google AdMob publishers,
follow instructions at https://googlemobileadssdk.page.link/admob-ios-update-plist
to set a valid application ID.
Google Ad Manager publishers,
follow instructions at https://googlemobileadssdk.page.link/ad-manager-ios-update-plist.'
plist 에도 추가해줘야 하나봄.
// Info.plist
<key>GADApplicationIdentifier</key>
<string>ca-app-pub000~000</string>
3-2. 재실행
굳!
4. Usage
import { RewardedAd, TestIds, RewardedAdEventType } from '@react-native-firebase/admob';
const getAds = () => {
try {
const rewarded = RewardedAd.createForAdRequest(TestIds.REWARDED, {
requestNonPersonalizedAdsOnly: true,
});
rewarded.onAdEvent((type, error, reward) => {
if (error) {
console.log('동영상을 불러오는 중 오류가 발생했어요', error);
}
if (type === RewardedAdEventType.LOADED) {
// 동영상 로드 완료
rewarded.show(); // 동영상 광고 띄우기
}
if (type === RewardedAdEventType.EARNED_REWARD) {
console.log('User earned reward of ', reward);
}
});
rewarded.load();
} catch (error) {
console.log('catch error', error);
}
}
4-1. 주의
TestId를 사용하지 않고 실제 광고단위의 unit id를 사용하여 개발을 진행하면 계정이 정지될 수도 있다고 한다.
테스트하면서 비정상적을 광고를 많이 불러오기 때문에!
4-2. 에러
Ad request successful, but no ad returned due to lack of ad inventory
if (error) 에서 걸린 에러다.
test unit id 말고 내가 admob에서 만든 앱의 광고 unit id를 넣었더니 이 에러가 떴는데,
애드몹 계정을 당일에 만들고 애드몹 내에 앱도 당일에 추가한거라서 아직 애드몹에서 광고를 준비하지 못한 것이다.
플레이 가능한 광고는 좀 더 기다려보고, 일단은 test unit id로 테스트 해보자!
(참고 블로그)
React Native Admob 광고 띄우기 - Vlee's Tale
테스트 ID Admob 테스트 시 시뮬레이터에서 광고를 띄우려고 하면 광고가 노출되지 않는 걸 알 수 있다. 테스트 용도로는 테스트 ID 사용하도록 되어 있다. Always test with test ads When building and testing yo
vlee.kr
dev-yakuza.github.io/ko/react-native/react-native-firebase-admob/
Firebase Admob
react-native-firebase 라이브러리를 사용하여 Google Admob을 표시해보자.
dev-yakuza.github.io
Google AdMob 광고 적용하기 (1/2)
import { firebase } from '@react-native-firebase/admob'; AdMob 이 포스팅을 읽고 계시는 여러분.... react-native 를 통하여 앱을 제작하고, 앱스토어에 어플리케이션을 업로드 했거나, 업로드 예정일 것입니..
richwind.co.kr
Google AdMob 광고 적용하기 (2/2)
너무 길어서 이전 포스팅에 이어서 진행 합니다. https://windflex.tistory.com/81 3단계 : Firebase SDK 적용 Credential 파일을 다운로드하여 지정된 위치에 저장하였다면, 이제 Firebase SDK를 실행합니다. 그..
richwind.co.kr
'Solve Problem > React Native' 카테고리의 다른 글
[React Native] Custom Font 적용 (Google Fonts) (0) | 2020.09.12 |
---|---|
[React Native] Sentry로 로그 이벤트 확인하기 (1) | 2020.09.01 |
[React Native] Deep Link 딥링크 (0) | 2020.08.24 |
[React Native] 앱 화면 캡쳐 후 공유 및 갤러리에 저장하기 (Capture ScreenShot and Share) (0) | 2020.08.18 |
[React Native] 관리자용 테스트앱 만들기 (0) | 2020.08.15 |