我是一个简单的uwp应用程序(在Microsoft / Windows Store中发布),我的主页面中只有一个广告(横幅)。我想在用户进行应用内购买时删除广告。 我已经按照Microsoft和Microsoft Virtual Academy的教程进行了操作,但我无法删除该广告!
private async void removeAds_Click(object sender, RoutedEventArgs e)
{
if (!AppLicenseInformation.ProductLicenses["RemoveAdsOffer"].IsActive)
{
try
{
// The customer doesn't own this feature, so
// show the purchase dialog.
PurchaseResults results = await CurrentAppSimulator.RequestProductPurchaseAsync("RemoveAdsOffer");
//Check the license state to determine if the in-app purchase was successful.
if (results.Status == ProductPurchaseStatus.Succeeded)
{
removeAds.Visibility = Visibility.Collapsed;
Ad.Visibility = Visibility.Collapsed;
}
}
catch (Exception ex)
{
// The in-app purchase was not completed because
// an error occurred.
throw ex;
}
}
else
{
// The customer already owns this feature.
}
}
我有广告(广告)和一个按钮(removeAds)来删除我主页上的广告!
广告和按钮已删除,但当我导航到我的应用的其他页面或关闭并重新打开该应用时,广告会重新显示。
答案 0 :(得分:0)
你期待什么?您只是在按钮单击上处理逻辑。一旦加载了另一个页面,逻辑就消失了。您需要检查并查看每个页面上是否ProductLicenses["RemoveAdsOffer"].IsActive
。