InterstitialAd 不适用于 Windows Phone 10 (UWP - Windows 10)

InterstitialAd not working with Windows Phone 10 (UWP - Windows 10)

在 Windows Phone 模拟器上 运行 时,我无法让 InterstitialAd 在我的 UWP 应用程序中工作(请注意,我还没有尝试过在实际 phone)

当我在模拟器或本地计算机中 运行 我的 UWP 应用程序作为 Windows 商店应用程序时,它按预期工作。

有什么想法吗?

谢谢。

更新 - 1

这是我用来显示 InterstitialAd 的代码。在我的 MainPage.xaml.cs 中,我有以下代码:

public sealed partial class MainPage : Page
{
    private InterstitialAd interstitialAd;

    public MainPage()
    {
        this.InitializeComponent();

        // Instantiate the interstitial video ad
        interstitialAd = new InterstitialAd();

        // Attach event handlers
        interstitialAd.ErrorOccurred += OnAdError;
        interstitialAd.AdReady += OnAdReady;
        interstitialAd.Cancelled += OnAdCancelled;
        interstitialAd.Completed += OnAdCompleted;
    }
}

// This is an event handler for the interstitial ad. It is 
// triggered when the interstitial ad is ready to play.
private void OnAdReady(object sender, object e)
{
    // The ad is ready to show; show it.
    interstitialAd.Show();
}

// This is an event handler for the interstitial ad. It is 
// triggered when the interstitial ad is cancelled.
private void OnAdCancelled(object sender, object e)
{
}

// This is an event handler for the interstitial ad. It is 
// triggered when the interstitial ad has completed playback.
private void OnAdCompleted(object sender, object e)
{
}

// This is an error handler for the interstitial ad.
private void OnAdError(object sender, AdErrorEventArgs e)
{
}

我从他们的 UWP 商店示例中直接获取了这段代码,除了我不是从按钮启动它,而是在我的页面加载时启动它:

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    // Request an ad. When the ad is ready to show, 
    // the AdReady event will fire.

    // The application id and ad unit id are passed in here.
    // The application id and ad unit id can be obtained from Dev 
    // Center.
    // See "Monetize with Ads" at https://msdn.microsoft.com/
    // en-us/library/windows/apps/mt170658.aspx
#if DEBUG
    interstitialAd.RequestAd(AdType.Video, 
    "d25517cb-12d4-4699-8bdc-52040c712cab", "11389925");
#else
    interstitialAd.RequestAd(AdType.Video, 
    "d25517cb-12d4-4699-8bdc-52040c712cab", "11389925");
#endif
}

我暂时将 ApplicationId 和 UnitAdId 作为测试值,因为我还没有发布它,好吧,反正没有广告。

谢谢

更新 - 2:

我在各种事件中添加了一些调试日志,这就是我得到的:

Page_Loaded: 00:00:00.0001590
Page_Loaded - RequestAd: 00:00:00.0091840
OnAdReady - Elasped Time: 00:01:04.6923865
OnAdError: NetworkConnectionFailure : Media timeout occurred 
                                      during playback. - Elasped 
                                      Time: 00:00:08.1955928

触发 OnAdReady 需要 1 分钟多的时间,这真的很奇怪,然后我在 8 秒后收到 OnAdError,所以从这些日志中你会认为存在网络问题,但我的数据正在正确加载,这都是从网络服务中拉出来的,所以肯定有联系。我的 AdMediator 也按预期显示广告(好吧,有点!那是另一回事了!)。

我明天会尝试将它直接传输到我的 phone 看看它是否有任何不同,我将我的笔记本电脑插入以太网端口而不是使用无线但我的无线相当不错,所以我不确定为什么会出现网络连接错误。

上面的代码是正确的,并且确实可以在 Windows Phone 上与 UWP 一起使用,但在模拟器中效果不佳,因为:

  • 它在 none 时间歇性地生成网络连接错误。
  • 显示广告可能需要一分钟多的时间,但它最终会显示。

我刚刚将我的应用程序上传到商店并将其下载到我的 phone 并且它按预期工作。它会立即或在几秒钟内显示广告。

我建议您不要浪费太多时间通过 phone 模拟器尝试它,因为这似乎是主要问题。实施您的代码,然后直接在您的设备上对其进行测试,或者假设您尚未发布您的应用程序,则从商店下载它。

更新:

我只是想更新我的答案,因为我刚刚阅读了来自 UI and User Experience Guidelines 的插页式广告的注意事项以及我实际做这件事的方式,这是 UI and User Experience Guidelines 中的要点之一=31=]列表。

它建议您提前 30-60 秒获取广告并且在应用程序启动时不显示它,这正是我正在做的,所以我想我会改变这方面的逻辑.