Google Ads
一种将所有 Google 广告轻松添加到您的 Flutter 应用的方法。
如何使用它
-
使用
flutter pub add google_mobile_ads添加 google_mobile_ads 包。 -
按照以下方式更新您的 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>
- 将 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>
-
在
if(kReleaseMode)内部的 ads.dart 中添加 id(rewardedID &&interstitialID && bannerID)。 -
要使用横幅广告,只需在任何小部件内编写
AdBanner()。 -
要使用激励广告,只需在
initState()方法中编写AdReWarded.instance.createRewardedAd(),并在dispose()方法中编写AdReWarded.instance.dispose。 -
要使用插页式广告,只需在
initState()方法中编写AdInterstitial.instance.createInterstitialAd(),并在dispose()方法中编写AdInterstitial.instance.dispose。