Windows Phone 8.1和CurrentAppSimulator

5
我正在尝试为我的通用应用程序添加应用内购买功能,在Windows Phone版本中测试时遇到了问题。指南中提到,为了使用CurrentAppSimulator,我必须“自定义名为“WindowsStoreProxy.xml”的文件,位于%userprofile%\AppData\local\packages\<package name>\LocalState\Microsoft\Windows Store\ApiData”。但是我无法在手机上执行此操作,因为我无法访问手机的文件系统。我该如何启用CurrentAppSimulator
3个回答

9
  • 适用于 Windows Phone 8.1、Dev Studio 2013。

您可以使用位于此处的 "ISETool" 访问隔离存储文件: "Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Tools\IsolatedStorageExplorerTool"。 如何使用 Windows Phone 8 隔离存储浏览器工具。 将它们复制到计算机上的文件夹后,您将拥有一个子文件夹 "IsolatedStore"。在 "\Microsoft\Windows Store\ApiData" 中,您将找到 "WindowsStoreProxy.xml" 文件:

<?xml version="1.0" encoding="utf-16" ?>
<CurrentApp>
    <ListingInformation>
        <App>
        <AppId>00000000-0000-0000-0000-000000000000</AppId>
        <LinkUri>http://apps.microsoft.com/webpdp/app/00000000-0000-0000-0000-000000000000</LinkUri>
        <CurrentMarket>en-US</CurrentMarket>
        <AgeRating>3</AgeRating>
        <MarketData xml:lang="en-us">
            <Name>AppName</Name>
            <Description>AppDescription</Description>
            <Price>1.00</Price>
            <CurrencySymbol>$</CurrencySymbol>
            <CurrencyCode>USD</CurrencyCode>
        </MarketData>
    </App>
    <Product ProductId="1" LicenseDuration="0" ProductType="Durable">
        <MarketData xml:lang="en-us">
            <Name>Product1Name</Name>
            <Price>1.00</Price>
            <CurrencySymbol>$</CurrencySymbol>
            <CurrencyCode>USD</CurrencyCode>
        </MarketData>
    </Product>
    <Product ProductId="2" LicenseDuration="0" ProductType="Consumable">
        <MarketData xml:lang="en-us">
            <Name>Product2Name</Name>
            <Price>1.00</Price>
            <CurrencySymbol>$</CurrencySymbol>
            <CurrencyCode>USD</CurrencyCode>
        </MarketData>
    </Product>
</ListingInformation>
<LicenseInformation>
    <App>
        <IsActive>true</IsActive>
        <IsTrial>true</IsTrial>
    </App>
    <Product ProductId="1">
        <IsActive>true</IsActive>
    </Product>
</LicenseInformation>
<ConsumableInformation>
    <Product ProductId="2" TransactionId="00000000-0000-0000-0000-000000000000" Status="Active" />
</ConsumableInformation>

将此文件复制到您的资产文件夹中,并将其包含在项目中。如果需要更改该文件,则需要将ProductId从“1”更改为“您的产品ID”。如果您不需要应用内可消耗商品,则可以删除产品ID为“2”的产品。将第二个许可证信息更改为:

<LicenseInformation>
    <App>
        <IsActive>true</IsActive>
        <IsTrial>false</IsTrial>
    </App>
    <Product ProductId="Your Product ID">
        <IsActive>false</IsActive>
    </Product>
</LicenseInformation>

让您的应用程序构造函数看起来像这样:

将应用程序的构造函数设置为以下内容:

private static LicenseInformation licenseInformation=null;
public App()
    {
        this.InitializeComponent();
        this.Suspending += this.OnSuspending;

#if DEBUG
        licenseInformation = CurrentAppSimulator.LicenseInformation;
#else
        licenseInformation = CurrentApp.LicenseInformation; 
#endif
        licenseInformation.LicenseChanged += licenseInformation_LicenseChanged;            
    }

添加事件处理程序:

private static void licenseInformation_LicenseChanged()
{
    if (licenseInformation.ProductLicenses["Your Product ID"].IsActive)
    {
        // add code for purchased (e.g. property of a data class derived from INotifyPropertyChanged)
    }
    else
    {
        // add code for not yet purchased (e.g. property of a data class derived from INotifyPropertyChanged)
    }
}

将以下内容添加到您的App类中:
public static async void RequestFeatureXYZ()
    {
        if (!licenseInformation.ProductLicenses["Your Product ID"].IsActive)
        {
            try
            {
#if DEBUG
                StorageFolder installFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
                StorageFile appSimulatorStorageFile = await installFolder.GetFileAsync("WindowsStoreProxy.xml");                                      

                await CurrentAppSimulator.ReloadSimulatorAsync(appSimulatorStorageFile);
                PurchaseResults result = await CurrentAppSimulator.RequestProductPurchaseAsync("Your Product ID");
#else
                PurchaseResults result = await CurrentApp.RequestProductPurchaseAsync("Your Product ID");
#endif
                // licenseInformation_LicenseChanged(); // (un)comment if you find out that the event does (not) always fire                }
            catch (Exception ex)
            {
                // handle error or do nothing
            }
        }            
    }

还有参考资料...

using Windows.Storage;
using Windows.Storage.Streams;
using Windows.ApplicationModel.Store;
using System.ComponentModel;

感谢提供详细信息!我已经成功显示了对话框并触发了事件。然而,我不确定该怎么做。当我连续两次请求该功能时,我感觉购买并没有传播。我应该如何告诉LicenseInformation对象应用程序不再处于试用模式?谢谢! - Timothée Bourguignon

1
他们提供了一个API来完成这个操作。你需要使用Windows.ApplicationModel.Store.CurrentAppSimulator.ReloadSimulatorAsync(IStorageFile file)并将其指向包含的“WindowsStoreProxy.xml”文件。该文件的结构与在Windows 8.1应用程序中使用的相同。

0

更详细的内容请参考之前的答案:

1.在您的解决方案中创建名为“Data”的文件夹,并添加WindowsStoreProxy.xml文件(或其他名称)。

2.在属性文件中设置“要复制的输出目录”为“复制较新版本”。

  • 使用此方法:

     public static async Task ConfigureSimulatorAsync()
    {
        var proxyFile = await Package.Current.InstalledLocation.GetFileAsync(@"data\WindowsStoreProxy.xml");
        await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
    }
    
    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        await MainPage.ConfigureSimulatorAsync();
    }
    

  • 网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接