0

我用 Flutter 制作了一个应用程序,并在 AdMob 的帮助下在其中实现了插页式广告。我在本教程https://codelabs.developers.google.com/codelabs/admob-ads-in-flutter#7的帮助下,对它进行了一些修改,因为我的应用程序中有一个侧面导航抽屉,我想在其中实施插页式广告。所以我实现的是:

  • 我为导航抽屉创建了一个不同的类,名为 adserviceNavDrawer。
  • 在该课程中,我使用了一些函数来实现广告:
    if (Platform.isAndroid){
      return "ca-app-pub-3940256099942544/8691691433";
    } else if (Platform.isIOS){
      return "ca-app-pub-3940256099942544/8691691433";
    } else{
      throw new UnsupportedError("Unsupported Platform");
    }
  }

  static InterstitialAd interstitialAd1;
  int _numInterstitialLoadAttempts = 0;

  static initialize() {
    if (MobileAds.instance == null) {
      //print("initialize:AdMob");
      MobileAds.instance.initialize();
    }
  }

  void createInterstitial1Ad() {
    InterstitialAd.load(
        adUnitId: interstital1,
        request: AdRequest(keywords: keywordsRequest),
        adLoadCallback: InterstitialAdLoadCallback(
          onAdLoaded: (InterstitialAd ad) {
            print('$ad loaded');
            interstitialAd1 = ad;
            _numInterstitialLoadAttempts = 0;
          },
          onAdFailedToLoad: (LoadAdError error) {
            print('InterstitialAd failed to load: $error.');
            _numInterstitialLoadAttempts += 1;
            interstitialAd1 = null;
            if (_numInterstitialLoadAttempts <= maxFailedLoadAttempts) {
              createInterstitial1Ad();
            }
          },
        ));
  }

  void showInterstitial1Ad(BuildContext context) {
    if (interstitialAd1 == null) {
      //print('Warning: attempt to show interstitial before loaded.');
      Navigator.push(context, MaterialPageRoute(builder: (context) => view1()));
      return;
    }
    interstitialAd1.fullScreenContentCallback = FullScreenContentCallback(
      onAdShowedFullScreenContent: (InterstitialAd ad) =>
          print('ad onAdShowedFullScreenContent.'),
      onAdDismissedFullScreenContent: (InterstitialAd ad) {
        print('$ad onAdDismissedFullScreenContent.');
        ad.dispose();
        createInterstitial1Ad();
        Navigator.push(context, MaterialPageRoute(builder: (context) => view1()));
      },
      onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) {
        print('$ad onAdFailedToShowFullScreenContent: $error');
        ad.dispose();
        createInterstitial1Ad();
      },
    );
    interstitialAd1.show();
    interstitialAd1 = null;

  }

  @override
  void dispose1() {
    interstitialAd1?.dispose();
  }
  • 然后我在导航抽屉类中调用createInterstitial1Ad()函数initState()
  • 然后在导航抽屉的按钮中我打电话showInterstitial1Ad()

我正在为导航抽屉中的所有按钮实施相同的步骤,但使用 AdMob 提供的不同广告单元 ID。

我没有购买任何流量,也没有请人为我推广,我通过 WhatsApp、Facebook、Instagram 和 YouTube 进行了所有推广,在推广我的应用程序时,我使用了应用程序的描述和功能,我已经给出了在描述中播放应用程序的商店链接。

我遵循了 AdMob 的所有指导方针,没有做错任何事来故意获得收入。我只是想知道为什么会发生这种情况,我非常感谢任何建议或解决方案。

请帮我解决一下这个。

感谢您提前回复。

4

0 回答 0