
โ ์ค์น ๋ฐ ํ ์คํธ
npm install react-native-google-mobile-ads
<app.json>
๋ฃจํธ์ test id๋ฅผ ์ ์ด์ค๋ค.
"react-native-google-mobile-ads": {
"android_app_id": "ca-app-pub-3940256099942544~3347511713",
"ios_app_id": "ca-app-pub-3940256099942544~1458002511"
},
Initialize
<index.tsx>
import mobileAds, { MaxAdContentRating } from "react-native-google-mobile-ads";
async function initAds() {
await mobileAds().setRequestConfiguration({
testDeviceIdentifiers: ["EMULATOR"],
maxAdContentRating: MaxAdContentRating.PG,
});
await mobileAds().initialize();
}
initAds();
Banner
import {
BannerAd,
BannerAdSize,
TestIds,
} from "react-native-google-mobile-ads";
BannerAd unitId={TestIds.BANNER} size={BannerAdSize.BANNER} />
ํน์ ๋์ ์ ์ ์ฒดํ๋ฉด์ผ๋ก ๊ด๊ณ ๋ณด์ฌ์ฃผ๊ธฐ
import {
AdEventType,
InterstitialAd,
TestIds,
} from "react-native-google-mobile-ads";
const onSubmit = () => {
if (selectedEmotion === "" || feelings === "") {
return Alert.alert(
"์ด๋ชจ์ง์ ๋ด์ฉ ๋ชจ๋ ์ ์ด์ฃผ์ธ์ฉ.",
"์ ์ ์ผ๋ฉด ์์ฝ๊ฒ ๋๊ฑฐ์ฃต",
);
}
realm?.write(() => {
realm.create("Feeling", {
_id: Date.now(),
emotion: selectedEmotion,
message: feelings,
});
});
const interstitialAd = InterstitialAd.createForAdRequest(
TestIds.INTERSTITIAL,
{
requestAgent: "CoolAds",
},
);
const unsubscribe = interstitialAd.addAdEventListener(
AdEventType.LOADED,
() => {
interstitialAd.show();
},
);
interstitialAd.addAdEventListener(AdEventType.CLOSED, () => {
unsubscribe();
goBack();
});
interstitialAd.load();
};
Reward
import {
AdEventType,
RewardedAdEventType,
RewardedInterstitialAd,
TestIds,
} from "react-native-google-mobile-ads";
const onSubmit = () => {
if (selectedEmotion === "" || feelings === "") {
return Alert.alert(
"์ด๋ชจ์ง์ ๋ด์ฉ ๋ชจ๋ ์ ์ด์ฃผ์ธ์ฉ.",
"์ ์ ์ผ๋ฉด ์์ฝ๊ฒ ๋๊ฑฐ์ฃต",
);
}
const cleanup = () => {
unsubscribeLoaded();
unsubscribeRewarded();
unsubscribeClosed();
};
const rewardedInterstitialAd = RewardedInterstitialAd.createForAdRequest(
TestIds.REWARDED_INTERSTITIAL,
);
const unsubscribeLoaded = rewardedInterstitialAd.addAdEventListener(
RewardedAdEventType.LOADED,
() => rewardedInterstitialAd.show(),
);
const unsubscribeRewarded = rewardedInterstitialAd.addAdEventListener(
RewardedAdEventType.EARNED_REWARD,
() => {
realm?.write(() => {
realm.create("Feeling", {
_id: Date.now(),
emotion: selectedEmotion,
message: feelings,
});
});
},
);
const unsubscribeClosed = rewardedInterstitialAd.addAdEventListener(
AdEventType.CLOSED,
() => {
cleanup();
goBack();
},
);
rewardedInterstitialAd.load();
};'๐ธ Third-Party Services' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Third-Party Services - Twilio (0) | 2025.06.02 |
|---|