facebook twitter hatena line email

Javascript/reactnative/admob/expo

提供: 初心者エンジニアの簡易メモ
2020年7月16日 (木) 17:07時点におけるAdmin (トーク | 投稿記録)による版 (setTestDeviceIDAsyncのfunctionは存在しないと出たとき)

移動: 案内検索

admob-expoの公式

https://docs.expo.io/versions/latest/sdk/admob/

admobプラグインのインストール

$ expo install expo-ads-admob

app.json にandroidとiosを追加

{
  "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
      }
    }
  }
}

setTestDeviceIDAsyncのfunctionは存在しないと出たとき

以下エラーが出たとき

[Unhandled promise rejection: TypeError: _expoAdsAdmob.AdMobInterstitial.setTestDeviceIDAsync is not a function.

以下のように対応する

import {
  AdMobBanner,
  AdMobInterstitial,
  AdMobRewarded,
  setTestDeviceIDAsync,
} from 'expo-ads-admob';
await setTestDeviceIDAsync('EMULATOR');
AdMobInterstitial.setTestDeviceID is deprecated. Test device IDs are now set globally. Use AdMob.setTestDeviceIDAsync instead.

setTestDeviceIDでなく、setTestDeviceIDAsyncを使う

参考

https://honmushi.com/2019/11/28/expo-admob/