gpt4 book ai didi

c# - 内购成功后正确步骤

转载 作者:太空狗 更新时间:2023-10-29 22:27:16 26 4
gpt4 key购买 nike

我尝试使用以下代码进行应用内购买。我正在使用 CurrentAppSimulator 进行测试。

private async void history_Click(object sender, RoutedEventArgs e)
{
bool OK = true;

// Get the license info
// The next line is commented out for testing.
// licenseInformation = CurrentApp.LicenseInformation;

// The next line is commented out for production/release.
LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
if (!licenseInformation.ProductLicenses["PremiumFeatures"].IsActive)
{
try
{
// The customer doesn't own this feature, so
// show the purchase dialog.

await CurrentAppSimulator.RequestProductPurchaseAsync("PremiumFeatures", false);
// the in-app purchase was successful
OK = true;
}
catch (Exception)
{
// The in-app purchase was not completed because
// an error occurred.
OK = false;
}
}
else
{
// The customer already owns this feature.
OK = true;
}

if (OK)
{
Frame.Navigate(typeof(HistoryPage));
}
}

但是,每次我执行history_Click 时,对话框一直弹出,即使我选择了 S_OK。我希望在购买 PremiumFeatures 之后,licenseInformation.ProductLicenses["PremiumFeatures"].IsActive 应该更改为 true。

enter image description here

我想,也许当应用内购买成功时,我需要打开 IsActive 标志,这样它就不会再显示购买对话框了。

        // the in-app purchase was successful
OK = true;
// Compile error!!!
licenseInformation.ProductLicenses["PremiumFeatures"].IsActive = true;

好的。似乎 IsActive 是一个只读字段。那么,请问购买成功案例的正确处理方式是什么?

更新:

看了Trial app and in-app purchase sample之后,我意识到在购买成功后,具有以下代码可以将 IsActivefalse 更改为 true 自动(但它为什么有效?)

    private async Task LoadInAppPurchaseProxyFileAsync()
{
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");
licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario);
CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

// setup application upsell message
ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();
var product1 = listing.ProductListings["product1"];
var product2 = listing.ProductListings["product2"];
Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + ".";
Product2SellMessage.Text = "You can buy " + product2.Name + " for: " + product2.FormattedPrice + ".";
}

但是,“已购买”状态不是持久性。如果我关闭应用程序并重新启动它,它会认为我的“高级功能”为“尚未购买”。

我认为如何使这种行为持久化?

最佳答案

请阅读

根据您的经验,我假设 App.IsTrial 设置为 true。当应用程序处于试用模式或(出于任何其他原因)未激活时,您无法进行购买。请注意,我指的是应用程序而不是功能/产品。一旦应用程序激活,您的购买就会成功。

关于c# - 内购成功后正确步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13965682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com