微软官方广告平台撤销了,只能找第三方.随后找到之前unity游戏里用过的Vungle,在uwp平台也是可以的.
前往vungle.com注册账号,然后根据提示,集成广告sdk.
然后发现一个坑:
集成后发现只有全屏广告的状态是可播放的.
但我想要局部广告,设置的placement状态一直是无法播放
---
最后尝试使用可播放的全屏广告的placement进行局部展示,根据局部广告的展示方式也可以完成局部广告.
这还要Mrec广告的placement干什么?!
xaml代码
<UI:VungleAdControl IsEnabled="True" x:Name="embeddedControl" Background="#FFAE4F4F" Grid.Row="2" Height="250" Width="300" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5"> <UI:VungleAdControl.RenderTransform> <CompositeTransform ScaleX="0.85" ScaleY="0.85" /> </UI:VungleAdControl.RenderTransform> </UI:VungleAdControl>
Cs
string appID = "********"; string placement = "********"; sdkInstance = AdFactory.GetInstance(appID); sdkInstance.UpdateConsentStatus(VungleConsentStatus.VungleConsentAccepted, "1.0"); //sdkInstance.LoadAd("******"); Debug.WriteLine("~~~~"); sdkInstance.OnAdPlayableChanged += async (vs, ve) => { Debug.WriteLine($"廣告播放狀態變化{ve.Placement}:{ve.AdPlayable.ToString()}"); if (ve.AdPlayable == true) { Debug.WriteLine($"{ve.Placement} Vungle可播放~~~~"); if (true)//ve.Placement== placement { await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(async () => { Debug.WriteLine($"播放局部广告"); //Play ad for placement2 embeddedControl.AppID = appID; embeddedControl.Placements = "DEFAULT-4880469,1-6727943,2-6846095"; embeddedControl.Placement = ve.Placement; embeddedControl.SoundEnabled = false; //embeddedControl.OnAdStart += Embedded_OnAdStart; //embeddedControl.OnAdEnd += Embedded_OnAdEnd; embeddedControl.AdConfig.Volume = 1.0; var nEmb = await embeddedControl.PlayAdAsync(); })); } else { Debug.WriteLine($"不播放"); } } };