Search Unity

Can't add google ads

Discussion in 'Windows' started by dreamhst7, Mar 27, 2014.

  1. dreamhst7

    dreamhst7

    Joined:
    Mar 27, 2014
    Posts:
    13
    When i run my unity3d apps in visual studio for windows phone with google ads it's not working, because some exception happens:
    "Exception type System.UnauthorizedAccessException in System.Windows.ni.dll ..
    "Exception type System.UnauthorizedAccessException in Microsoft.Phone.Interop.ni.dll
    "Exception type System.Reflection.TargetInvocationException in mscorlib.ni.dll
    "Exception type System.IO.FileNotFoundException in mscorlib.ni.dll
    "Exception type MS.Internal.NativeParseException in System.Windows.ni.dll

    MainPage.xaml.cs

    var bridge = new UnityBridge();
    Grid ContentPanel;
    UnityApp.SetBridge(bridge);
    InitializeComponent();
    // NOTE: Edit "MY_AD_UNIT_ID" with your ad unit id.
    AdView bannerAd = new AdView
    {
    Format = AdFormats.Banner,
    AdUnitID = "ca-app-pub-xxxxx/xxxx"
    };
    bannerAd.ReceivedAd += OnAdReceived;
    bannerAd.FailedToReceiveAd += OnFailedToReceiveAd;
    ContentL.Children.Add(bannerAd);
    AdRequest adRequest = new AdRequest();
    adRequest.ForceTesting = false;
    bannerAd.LoadAd(adRequest);
    bridge.Control = DrawingSurfaceBackground;

    MainPage.xaml is
    <DrawingSurfaceBackgroundGrid x:Name="DrawingSurfaceBackground" Loaded="DrawingSurfaceBackground_Loaded">
    <GoogleAds:AdView HorizontalAlignment="Left" Margin="27,688,0,0" VerticalAlignment="Top"/>
    <GoogleAds:AdView HorizontalAlignment="Left" Margin="48,542,0,0" VerticalAlignment="Top"/>
    <Grid Name="ContentL" />
    </DrawingSurfaceBackgroundGrid>

    What code are needs in MainPage.xaml? or some other features?
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,900
    Maybe you're missing some capabilities in Package.appxmanifest, I would imagine ads need Internet Client capabilities enabled.

    Also, enable excpetions via Debug->Exceptions, so VS would stop at the exception, and you can inspect it.