简体   繁体   English

删除广告(应用内购买)UWP应用

[英]Remove Ads (In-App Purchase) UWP App

I am a simple uwp app (published in Microsoft/Windows Store), and I have only an ad (banner) in my main page. 我是一个简单的uwp应用程序(在Microsoft / Windows Store中发布),我的主页上只有一个广告(横幅)。 I want remove the ad when user makes in-app purchase. 我想在用户进行应用内购买时删除广告。 I have already followed tutorials from Microsoft and Microsoft Virtual Academy but I can not remove the ad! 我已经按照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.
            }
}

I have the ad (Ad) and a button (removeAds) to remove the advertising on my main page! 我有一个广告(Ad)和一个按钮(removeAds),可以删除主页上的广告!

The ad and button are removed but when I navigate to another page of my app or close and reopen the app, the ad reappears. 广告和按钮已删除,但是当我导航到应用程序的另一个页面或关闭并重新打开该应用程序时,该广告会重新出现。

What do you expect? 你能指望什么? You're only processing the logic on the button click. 您仅在单击按钮时处理逻辑。 As soon as another page is loaded, the logic is gone. 一旦加载了另一页,逻辑就消失了。 You'll need to check and see if ProductLicenses["RemoveAdsOffer"].IsActive on every page load. 您需要检查并在每次加载页面时查看ProductLicenses["RemoveAdsOffer"].IsActive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM