AdMob-iOS实施RewardBasedVideoAd

时间:2018-11-08 09:02:48

标签: c# ios xamarin.forms admob admob-rewardedvideoad

我正在尝试在Xamarin中使用C#为iOS实施RewardBasedVideoAd,但似乎无法正常工作。到目前为止,这就是我所掌握的内容,并且没有涉及任何委托函数。任何帮助或建议,我们将不胜感激。预先感谢。

    public class AdMobImplementation : UIViewController, 
    IRewardBasedVideoAdDelegate
    {
        public AdMobImplementation()
        {
            RewardBasedVideoAd.SharedInstance.Delegate = this;
RewardBasedVideoAd.SharedInstance.LoadRequest(Request.GetDefaultRequest(), "ca-app-pub-3940256099942544/1712485313");
            }
        public void DidRewardUser(RewardBasedVideoAd rewardBasedVideoAd, AdReward reward)
        {
            Console.WriteLine("rewarded");
        }

     public void DidFailToLoad(RewardBasedVideoAd rewardBasedVideoAd, NSError error)
        {
            Console.WriteLine($"Reward based video ad failed to load with error: {error.LocalizedDescription}.");
        }

        public void DidReceiveAd(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad is received.");
        }

        public void DidOpen(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Opened reward based video ad.");
        }

        public void DidStartPlaying(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad started playing.");
        }

        public void DidClose(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad is closed.");
        }

        public void WillLeaveApplication(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad will leave application.");
        }
}

2 个答案:

答案 0 :(得分:1)

问题终于解决了! 您无需处理IRewardBasedVideoAdDelegate。 您所需要做的就是从RewardBasedVideoAdDelegate继承您的类,并覆盖所有必需的方法,例如:

public class AdMobImplementation : RewardBasedVideoAdDelegate
    {
        public AdMobImplementation()
        {
            RewardBasedVideoAd.SharedInstance.Delegate = this;
RewardBasedVideoAd.SharedInstance.LoadRequest(Request.GetDefaultRequest(), "ca-app-pub-3940256099942544/1712485313");
            }
        public override void DidRewardUser(RewardBasedVideoAd rewardBasedVideoAd, AdReward reward)
        {
            Console.WriteLine("rewarded");
        }

     public override void DidFailToLoad(RewardBasedVideoAd rewardBasedVideoAd, NSError error)
        {
            Console.WriteLine($"Reward based video ad failed to load with error:{error.LocalizedDescription}.");
        }

        public override void DidReceiveAd(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad is received.");
        }

        public override void DidOpen(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Opened reward based video ad.");
        }

        public override void DidStartPlaying(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad started playing.");
        }

        public override void DidClose(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad is closed.");
        }

        public override void WillLeaveApplication(RewardBasedVideoAd rewardBasedVideoAd)
        {
            Console.WriteLine("Reward based video ad will leave application.");
        }
}

希望这对寻求解决方案的人有所帮助:)

答案 1 :(得分:0)

原因: 与BannerView不同。因为您使用的是Google提供的testUnitID,所以需要设置TestDeviceId。您将在

之类的输出中获得错误信息
  

要在此设备上获取测试广告,请致电:request.testDevices =   @ [kGADSimulatorID]或@ [@“ xxxxxxxxxxx”](如果您使用的是真实设备;

解决方案:

  

如果您使用模拟器

var request = Request.GetDefaultRequest();
request.TestDevices = new[] {Request.SimulatorId.ToString() };
RewardBasedVideoAd.SharedInstance.LoadRequest(Request.GetDefaultRequest(), "ca-app-pub-3940256099942544/1712485313");
  

如果您使用真实设备

var request = Request.GetDefaultRequest();
request.TestDevices = new[] {"xxxxxxxxxxxxx"};
RewardBasedVideoAd.SharedInstance.LoadRequest(Request.GetDefaultRequest(), "ca-app-pub-3940256099942544/1712485313");

我使用了上面的代码,它工作正常。