반응형
React Native앱을 만들다가 계속 문서 찾아보면서하기 어려워서
간략히 정리를 해두려고합니다.
우선 Visual Studio Code에서 시작하는 방법
Expo 설치하고, project생성
npm install --global expo-cli
expo init my-project
그 후,
Webview 사용시 필요한 부분
expo install react-native-webview
예시
import * as React from 'react';
import { WebView } from 'react-native-webview';
export default class App extends React.Component {
render() {
return <WebView source={{ uri: 'https://expo.io' }} style={{ marginTop: 20 }} />;
}
}
Google Admob 사용시 적용되는 부분
expo install expo-ads-admob
app.json 에 셋팅해줘야하는 부분
{
"expo": {
"name": "Ads Showcase",
// ...
"android": {
// ...
"config": {
// ...
"googleMobileAdsAppId": "ca-app-pub-3940256099942544~3347511713" // sample id, replace with your own
}
},
"ios": {
// ...
"config": {
// ...
"googleMobileAdsAppId": "ca-app-pub-3940256099942544~1458002511" // sample id, replace with your own
}
}
}
}
사용방법
import {
AdMobBanner,
AdMobInterstitial,
PublisherBanner,
AdMobRewarded,
setTestDeviceIDAsync,
} from 'expo-ads-admob';
// Set global test device ID
await setTestDeviceIDAsync('EMULATOR');
// Display a banner
<AdMobBanner
bannerSize="fullBanner"
adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
servePersonalizedAds // true or false
onDidFailToReceiveAdWithError={this.bannerError} />
// Display a DFP Publisher banner
<PublisherBanner
bannerSize="fullBanner"
adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
onDidFailToReceiveAdWithError={this.bannerError}
onAdMobDispatchAppEvent={this.adMobEvent} />
// Display an interstitial
await AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712'); // Test ID, Replace with your-admob-unit-id
await AdMobInterstitial.requestAdAsync({ servePersonalizedAds: true});
await AdMobInterstitial.showAdAsync();
// Display a rewarded ad
await AdMobRewarded.setAdUnitID('ca-app-pub-3940256099942544/5224354917'); // Test ID, Replace with your-admob-unit-id
await AdMobRewarded.requestAdAsync();
await AdMobRewarded.showAdAsync();
반응형
'프로그래밍 > App 개발' 카테고리의 다른 글
React Native Android Build 에러 해결 (0) | 2021.07.26 |
---|---|
React-native-webview back button (0) | 2020.06.07 |
[퍼온글]_BroadCastReceiver 에 대하여 (0) | 2020.04.21 |
안드로이드 개발자 모드 진입 방법 (0) | 2020.01.08 |
[Android] Intent 데이터 전송 (0) | 2019.01.31 |