1

我有一个 Windows 8 应用程序,我现在想把它放在商店里。AppSimulator 工作正常(即使当我单击“确定”时我无法将 IsActive 设置为“true”......但会弹出 MsgDialog 'Thanks'),但我不知道 CurrentApp 是否正确。我已经读过 IsActive 将自动设置为 true 而无需在代码中分配它。

关于下面的代码,我只有两个问题:

  1. CurrentApp 的代码可以工作吗?

  2. 由于当涉及到 CurrentApp 时我没有在 WindowsStoreProxy.xml 中分配任何内容,因为 Windows 会自动从商店加载此信息(不知道是否属实......我在某处读过),我怎么能说 ProductLicenses 在 WindowsStoreProxy.xml 中被称为“Premium”?在 CurrentAppSimulator 中这很容易,因为它从我的内部 XML 文件 in-app-purchase.xml 加载价格/名称/...,但是如何为真正的 App 设置 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();
        }
}
4

1 回答 1

0

您无需通过代码进行设置。CurrentAppSimulator 会自动完成。

只需检查您在 WindowsStoreProxy.xml 中的设置并确保将“IsTrial”设置为“假”-

<LicenseInformation>
    <App>
        <IsActive>true</IsActive>
        <IsTrial>false</IsTrial>
    </App>
    <Product ProductId="1">
        <IsActive>false</IsActive>
    </Product>
</LicenseInformation>
于 2013-05-09T17:24:31.173 回答