まず、デバッグ モードで CurrentAppSimulator を使用し、リリース モードで CurrentApp を使用する独自のクラス CurrentAppProxy を使用します。次に、このコードを使用して InApp 購入を購入すると、問題なく動作します。
try
{
await CurrentAppProxy.RequestProductPurchaseAsync(PremiumName, false);
// after closing the inApp purchase dialog, test, if it was bought
if (licenseInformation.ProductLicenses[PremiumName].IsActive)
{
// set the local flag
IsPremium = true;
dialog = new MessageDialog(resourceLoader.GetString("ThanksForPremium"));
await dialog.ShowAsync();
}
// else do not show anything
}
catch (Exception)
{
// failed buying the premium
dialog = new MessageDialog(resourceLoader.GetString("ErrorBuyingPremium"));
dialog.ShowAsync();
}
編集: これらのプロパティにアクセスする前に、これを使用してデバッグ モードで CurrentAppSimulator を初期化します。
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test-purchase.xml");
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
そして test-purchase.xml の一番下に私が得た:
<LicenseInformation>
<App>
<IsActive>true</IsActive>
<IsTrial>false</IsTrial>
</App>
<Product ProductId="premium">
<IsActive>false</IsActive>
</Product>
</LicenseInformation>