我正在使用适用于 UWP 的 Microsoft 广告 SDK:https ://marketplace.visualstudio.com/items?itemName=AdMediator.MicrosoftAdvertisingSDK并希望将原生广告添加到我的应用程序
这是演示该问题的代码:
auto NativeAdManager = ref new Microsoft::Advertising::WinRT::UI::NativeAdsManager("d25517cb-12d4-4699-8bdc-52040c712cab", "10043134");
NativeAdManager->AdReady += ref new Windows::Foundation::EventHandler<Platform::Object^>([](Platform::Object ^ s, Platform::Object ^ ad)
{
Platform::String^ Title = static_cast<Microsoft::Advertising::WinRT::UI::NativeAd^>(ad)->Title;
Platform::String^ desc = static_cast<Microsoft::Advertising::WinRT::UI::NativeAd^>(ad)->Description;
__debugbreak();
});
NativeAdManager->ErrorOccurred += ref new Windows::Foundation::EventHandler<Microsoft::Advertising::WinRT::UI::AdErrorEventArgs^>([](Platform::Object^ sender, Microsoft::Advertising::WinRT::UI::AdErrorEventArgs^ e) {
auto x = e->ErrorMessage;
__debugbreak();
});
NativeAdManager->RequestAd();
一旦RequestAd()
调用 get ,AdReady
事件处理程序就会按预期运行,但问题是广告数据是无稽之谈。例如Title
is nullptr
,Description
是一个无效的字符串句柄,AdIcon
是一个无效的图像类等。该ErrorOccurred
事件永远不会触发。Visual Studio 的调试输出窗口中也有一些奇怪的输出:
info:get_AppId() invoked. [Windows::ApplicationModel::Store::CurrentAppFactory::get_AppId]
The thread 0x3ce0 has exited with code 0 (0x0).
ERROR:ChkHr(spStoreCommerce->Initialize(HStringReference(wszCV).Get())) (0x803f6107) [Windows::ApplicationModel::Store::CurrentAppFactory::GetStoreCommerce]
ERROR:ChkHr(GetStoreCommerce(&spStoreCommerce)) (0x803f6107) [Windows::ApplicationModel::Store::CurrentAppFactory::get_AppId]
info:GetAppReceiptAsync() invoked. [Windows::ApplicationModel::Store::CurrentAppFactory::GetAppReceiptAsync]
ERROR:ChkHr(spStoreCommerce->Initialize(HStringReference(wszCV).Get())) (0x803f6107) [Windows::ApplicationModel::Store::CurrentAppFactory::GetStoreCommerce]
ERROR:ChkHr(GetStoreCommerce(&spStoreCommerce)) (0x803f6107) [Windows::ApplicationModel::Store::CurrentAppFactory::GetAppReceiptAsync]
WLID Error: 80860003Exception thrown at 0x00007FFA59024008 in Advertising.exe: Microsoft C++ exception: Concurrency::task_canceled at memory location 0x00000064AFDFF228.
我究竟做错了什么?