본문 바로가기
개발/Flutter

플러터 Flutter 구글 애드몹 Google Admob 전면 광고 간단 구현

by SPNK 2023. 3. 31.
반응형

패키지 정보

 

google_mobile_ads | Flutter Package

Flutter plugin for Google Mobile Ads, supporting banner, interstitial (full-screen), rewarded and native ads

pub.dev

 

  • 터미널 설치
 $ flutter pub add google_mobile_ads

 

안드로이드 설정

  • android / app / src / main / AndroidManifest.xml
<manifest>
    <application>
        <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    <application>
<manifest>

 

아이폰 설정

  • ios / Runner / Info.plist
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-################~##########</string>

 


  • main.dart 설정 (초기화)
void main() async {
  MobileAds.instance.initialize();

 

  • 광고 로드
AdManagerInterstitialAd? _interstitialAd;

  @override
  void initState() {
    super.initState();

    loadAd();
  }
  void loadAd() {
    AdManagerInterstitialAd.load(
        adUnitId: Platform.isAndroid
            ? '안드로이드 광고 id'
            : '아이폰 광고 id',
        request: const AdManagerAdRequest(),
        adLoadCallback: AdManagerInterstitialAdLoadCallback(
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            _interstitialAd = ad;
          },
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('AdManagerInterstitialAd failed to load: $error');
          },
        ));
  }

 

  • 광고 보여주기 (원하는 위치에)
_interstitialAd?.show();

 


참고할만한 글

 

 

전면 광고  |  Flutter 베타  |  Google Developers

전면 광고 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 전면 광고는 호스트 앱의 인터페이스를 완전히 덮는 전체 화면 광고입니다. 일반적으로 활동이 바

developers.google.com

 

반응형

댓글