简体   繁体   English

Flutter admob 通过 IAP 移除广告

[英]Flutter admob Remove ads by IAP

Hi I'm showing firebase admob banner and interstial ad with this way.It shows ads from firebase admob.Its signed to firebase嗨,我正在用这种方式展示 firebase admob 横幅和插页式广告。它显示来自 firebase admob 的广告。它已签署 firebase

import 'package:firebase_admob/firebase_admob.dart';
import 'dart:io';

class AdvertService {
  static final AdvertService _instance = AdvertService._internal();
  factory AdvertService() => _instance;
  MobileAdTargetingInfo _targetingInfo;

  final String _bannerAd = Platform.isAndroid
      ? 'ca-app-pub-xxxxxxx1/5xxxxxxxx'
      : 'ca-app-pub-xxxxxxx1/2xxxxxxxx';
  final String _interAd = Platform.isAndroid
      ? 'ca-app-pub-xxxxxxx1/1xxxxxxxx'
      : 'ca-app-pub-xxxxxxx1/6xxxxxxxx';
  // FirebaseAdMob.instance.initialize(appId: appId);

  AdvertService._internal() {
    //_targetingInfo = MobileAdTargetingInfo( testDevices: <String>["54a0a4f2"]);
    _targetingInfo = MobileAdTargetingInfo();
  }
  showBanner() {
    print(_bannerAd);
    BannerAd banner = BannerAd(
        adUnitId: _bannerAd,
        size: AdSize.smartBanner,
        targetingInfo: _targetingInfo);

    banner
      ..load()
      ..show();
    banner.dispose();
  }

  showIntersitial() {
    InterstitialAd interstitialAd =
        InterstitialAd(adUnitId: _interAd, targetingInfo: _targetingInfo);

    interstitialAd
      ..load()
      ..show();

    interstitialAd.dispose();
  }
}

and showing ads with并展示广告

final AdvertService _advertService = AdvertService();

_advertService.showBanner();

or
_advertService.showIntersitial();

What I want to do is make an IAP and remove ads from this user.How can I do it我想做的是制作 IAP 并从此用户中删除广告。我该怎么做

There are several ways for accomplishing what you're asking.有几种方法可以完成您的要求。
I suggest you to follow this tutorial:我建议您按照本教程进行操作:

https://fireship.io/lessons/flutter-inapp-purchases/ https://fireship.io/lessons/flutter-inapp-purchases/

and to install this package:并安装这个包:

https://pub.dev/packages/in_app_purchase https://pub.dev/packages/in_app_purchase

You will have to enable IAPs on your Google Play Console and/or AppStoreConnect.您必须在 Google Play 控制台和/或 AppStoreConnect 上启用 IAP。 Remember that using IAPs in an app is subject to Google's and/or Apple's terms of use, so pay attention to those terms.请记住,在应用程序中使用 IAP 受 Google 和/或 Apple 的使用条款的约束,因此请注意这些条款。
In addition, if you want to use "Consumables" (an item that can be purchased more that 1 time), you will have to store whether the user has purchased this item in your backend (for example in Firebase Cloud Firestore), since both Apple and Google are only able to store the information regarding if the user has purchased an item, and not how many time he has purchased it.此外,如果您想使用“消耗品”(可以购买超过 1 次的商品),您必须在后端存储用户是否购买了该商品(例如在 Firebase Cloud Firestore 中),因为两者都Apple 和 Google 只能存储有关用户是否购买过商品的信息,而不能存储有关用户购买商品的次数的信息。

Let me do a little consideration:让我稍微考虑一下:
Managing IAPs could be very painful, since it is not the simplest thing to do, especially in Flutter where the native capabilities are not directly managed by the developer.管理 IAP 可能非常痛苦,因为这不是最简单的事情,尤其是在 Flutter 中,原生功能不是由开发人员直接管理的。 If your goal is ONLY remove the ads if a user wants to pay a little amount of money (like for example 0.99€ or 1.20$), I suggest you to create 2 versions of the app, one with the ads and one without the ads, put the second version on sale on the stores and when the user clicks on "remove ads", open the corresponding store and prompt him to download the "premium version" of your app.如果您的目标只是在用户愿意支付少量费用(例如 0.99 欧元或 1.20 美元)时移除广告,我建议您创建 2 个版本的应用程序,一个有广告,一个没有广告,将第二个版本在商店发售,当用户点击“去除广告”时,打开相应的商店并提示他下载您的应用程序的“高级版”。 You'll save a lot of time and mental health!您将节省大量时间和心理健康!

Happy coding!快乐编码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM