【问题标题】:Microsoft advertising SDK for windows phone 8 (XAML)适用于 windows phone 8 (XAML) 的 Microsoft 广告 SDK
【发布时间】:2014-09-17 03:23:31
【问题描述】:

我想在我的应用中添加广告。

这是我的 XAML

    <Grid x:Name="ContentPanel" Margin="12,343,12,43" Grid.RowSpan="2">
        <UI1:AdControl Name="AdUnit" AdUnitId="test_client" 
                       ApplicationId="Image480_80" 
                       Height="80"  
                       VerticalAlignment="Bottom" />

这是我的代码

    public MainPage()
    {
        InitializeComponent();
        Thread.Sleep(1000);
        AdUnit.ErrorOccurred += AdUnit_ErrorOccurred;

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
    }
    void AdUnit_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("ad error " + e.Error.Message.ToString());
    }

当我将它部署到设备时,null reference 发生在

     AdUnit.ErrorOccurred += AdUnit_ErrorOccurred;

我关注了 MSDN 的所有内容。 我正在使用 VS2013。

【问题讨论】:

    标签: c# windows-phone-8


    【解决方案1】:

    确保您的 WMAppManifest 中包含所有这些 capabilities:

    ID_CAP_IDENTITY_USER
    ID_CAP_MEDIA_LIB
    ID_CAP_NETWORKING
    ID_CAP_PHONEDIALER
    ID_CAP_WEBBROWSERCOMPONENT
    

    一个示例 xaml:

    <my:AdControl Visibility="Visible" ErrorOccurred="OnAdError_ErrorOccurred" AdUnitId="10020750" ApplicationId="e1e3c23b-3a59-4119-852e-8ad0a7f78f11" Height="80" HorizontalAlignment="Left" Margin="-12,6,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
    

    .cs:

    using Microsoft.Advertising.Mobile.UI;
    
    namespace WP_AdApp
    {
    public partial class MainPage : PhoneApplicationPage
    {
        private AdControl adControl;
        private const string APPLICATION_ID = "e1e3c23b-3a59-4119-852e-8ad0a7f78f11";
        private const string AD_UNIT_ID = "10020750";
    
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
    
        private void OnAdError_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
        {
            MessageBox.Show("AdControl error: " + e.Error.Message);
        }
    }
    }
    

    更多信息请查看here

    希望对你有帮助!

    【讨论】:

    • 测试值在模拟器中有效,但在设备上有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    相关资源
    最近更新 更多