اذهب إلى المحتوى
  • 0

مشكلة عرض اعلانات RewardedVideoAd in flutter

Flutter Dev

السؤال

قمت بعمل كلاس منفصل لكلاس اعلانات RewardedVideoAd  من ادموب 

بشكل التالي:

import 'package:firebase_admob/firebase_admob.dart';


import 'helper.dart';




const String testDevice = '********';
class AdsReward {

  static int  _coins=0;

  static RewardedVideoAd videoAd = RewardedVideoAd.instance;

  static void initialize() {
    FirebaseAdMob.instance.initialize(appId: AdManager.appId);
  }

  static MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    testDevices: testDevice != null ? <String>[testDevice] : null,
    keywords: <String>['Game', 'Mario'],
    //contentUrl: 'https://flutter.io',
    //childDirected: true,
    nonPersonalizedAds: true,// Android emulators are considered test devices
  );

  static RewardedVideoAd _createRewardedVideoAd() {


    videoAd.load(adUnitId:AdManager.rewardedAdUnitId, targetingInfo: targetingInfo);
    RewardedVideoAd.instance.listener = (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
      if(event == RewardedVideoAdEvent.closed) {
        videoAd.load(adUnitId:AdManager.rewardedAdUnitId, targetingInfo: targetingInfo);


      }
    };

  }

  static void showRewardedVideoAd() {
    if (videoAd == null) videoAd = _createRewardedVideoAd();

    videoAd .show().catchError((e) =>
        print("error in showing ad: ${e.toString()}"));

  }


}

واقوم بستدعاه من الصفحة المستهدفة بشكل التالي :

 onPressed:  (){

              AdsReward.showRewardedVideoAd();


          },

ولكن اواجه مشكلة مع كل محاولة عرض للاعلان كالتالي:

error in showing ad: PlatformException(ad_not_loaded, show failed for rewarded video, no ad was loaded, null, null)

فيه احد يعرف سبب المشكلة وكيفية حلها لو تكرمتو

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

يبدو أن المشكلة أنه تقوم بالضغط على الزر قبل تحميل الإعلان وهنا يجب تمكين الزر الخاص بك فقط إذا تم تحميل الإعلان, يجب عليك الانتظار حتى يتم تحميل الإعلان, و في initState, يجب عليك تعيين حالة الزر الخاص بك وبهذه الطريقة سيتم تعطيله و  إذا تم تحميل الإعلان, يجب عليك استخدام setState لتمكين الزر.

 يمكنك استخدام Listener بهذا الشكل, 

RewardedVideoAd.instance.listener = (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
      if (event == RewardedVideoAdEvent.rewarded) {
        .....
      }

      if (event == RewardedVideoAdEvent.loaded) {
        //RewardedVideoAd.instance.show();
      }
};

وفي شرط يمكنك وضع setState لتمكين الزر.

event == RewardedVideoAdEvent.loaded

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...