Google Ads

一种将所有 Google 广告轻松添加到您的 Flutter 应用的方法。

如何使用它

  1. 使用 flutter pub add google_mobile_ads 添加 google_mobile_ads 包。

  2. 按照以下方式更新您的 Info.plist

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>cstr6suwn9.skadnetwork</string>
    </dict>
  </array>
  1. 将 AdMob 应用 ID(在 AdMob UI 中识别)添加到应用中的 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>
  1. if(kReleaseMode) 内部的 ads.dart 中添加 id (rewardedID &&interstitialID && bannerID)

  2. 要使用横幅广告,只需在任何小部件内编写 AdBanner()

  3. 要使用激励广告,只需在 initState() 方法中编写 AdReWarded.instance.createRewardedAd(),并在 dispose() 方法中编写 AdReWarded.instance.dispose

  4. 要使用插页式广告,只需在 initState() 方法中编写 AdInterstitial.instance.createInterstitialAd(),并在 dispose() 方法中编写 AdInterstitial.instance.dispose

GitHub

查看 Github