我有一个Windows 8应用程序,我想现在放在商店。 AppSimulator运行正常(即使我点击'确定'时无法将IsActive设置为'true'......但弹出MsgDialog'Thanks'),但我不知道CurrentApp是否正确。我已经读过,IsActive将自动设置为true而不在代码中指定它。
我对以下代码有两个问题:
CurrentApp的代码是否有效?
由于我在WindowsStoreProxy.xml中没有为CurrentApp分配任何东西,因为Windows会自动从商店加载这些信息(不知道是不是真的......我已经读过了在某处),我怎么能说ProductLicenses在WindowsStoreProxy.xml中被称为'Premium'?在CurrentAppSimulator中很容易,因为它从我的内部XML文件in-app-purchase.xml中加载价格/名称/ ...但是如何设置真实应用程序的XML文件?在Windows应用商店?
#if DEBUG
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);
#endif
#if DEBUG
LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
ListingInformation productListing = await CurrentAppSimulator.LoadListingInformationAsync();
#else
LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
ListingInformation productListing = await CurrentApp.LoadListingInformationAsync();
#endif
ProductLicense productLicense = licenseInformation.ProductLicenses["Premium"];
if (!productLicense.IsActive)
{
Buy()
}
else
{
//use full function
}
private async void Buy()
{
#if DEBUG
LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
#else
LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
#endif
if (!licenseInformation.ProductLicenses["Premium"].IsActive)
{
try
{
#if DEBUG
await CurrentAppSimulator.RequestProductPurchaseAsync("Premium", false);
#else
await CurrentApp.RequestProductPurchaseAsync("Premium", false);
#endif
if (licenseInformation.ProductLicenses["Premium"].IsActive)
{
try
{
MessageDialog msgDialog = new MessageDialog("Thanks for buying the app.");
await msgDialog.ShowAsync();
}
catch
{
}
}
else
{
MessageDialog msgDialog = new MessageDialog("The purchase was cancelled.");
await msgDialog.ShowAsync();
}
}
catch
{
MessageDialog msgDialog = new MessageDialog("Connection error.");
msgDialog.ShowAsync();
}
}
else
{
MessageDialog msgDialog = new MessageDialog("You already have this feature.");
await msgDialog.ShowAsync();
}
}
答案 0 :(得分:0)
您无需通过代码进行设置。 CurrentAppSimulator会自动执行此操作。
只需检查WindowsStoreProxy.xml中的设置,并确保'IsTrial'设置为'false' -
<LicenseInformation>
<App>
<IsActive>true</IsActive>
<IsTrial>false</IsTrial>
</App>
<Product ProductId="1">
<IsActive>false</IsActive>
</Product>
</LicenseInformation>