问题
I'm developing a uwp app, and I have in-app advertising (only on the main page) that can be removed by clicking in a button (in app purchase). I am using CurrentAppSimulator
(I am still testing) and I already have the removal of the advertising to be done successfully, but I have a problem. For example: I remove the advertising by clicking the button, then the button and the advertising disappear but if I navigate to another page of the app (for example to the settings) and return to the main page, the advertising is no longer displayed but it is there The button to remove the advertising.
This is my code (it removes the publicity and the button, when the button is clicked):
if (results.Status == ProductPurchaseStatus.Succeeded)
{
RemoveAds.Visibility = Visibility.Collapsed;
Ad.Visibility = Visibility.Collapsed;
}
In my XAML I have both elements (button and advertising) appear as: Visibility="Visible"
回答1:
When you reload the Main page (even when navigating back), that button is getting the Visibility setting from your XAML because that code above only runs when the button is clicked. You need to run similar code as the page loads, by overloading OnNavigatedTo method. In that method, you can check that the purchase has been made and set the RemoveAds.Visibility to Collapsed.
If you want to do this in your view model, you can have a property that returns the state of the purchase, and bind the RemoveAds.Visibility property to it.
来源:https://stackoverflow.com/questions/43052338/button-to-remove-ads-in-app-purchase-does-not-disappear