Windows Phone 8.1和CurrentAppSimulator

Nat*_*ond 5 c# windows-phone winrt-xaml windows-store-apps windows-phone-8.1

我正在尝试将应用内购买添加到我的通用应用中,并且无法在Windows Phone版本中对其进行测试.该指南说,为了使用CurrentAppSimulator我必须"自定义名称"WindowsStoreProxy.xml"中的文件%userprofile%\AppData\local\packages\<package name>\LocalState\Microsoft\Windows Store\ApiData".

我不能在手机上这样做,因为我无法访问手机的文件系统.我如何启用CurrentAppSimulator

A.J*_*uer 9

  • 适用于Windows Phone 8.1,Dev Studio 2013

您可以使用位于此处的"ISETool"访问隔离的存储文件:"Program Files(x86)\ Microsoft SDKs\Windows Phone\v8.0\Tools\IsolatedStorageExplorerTool". 如何使用Windows Phone 8的Isolated Storage Explorer工具.将它们复制到计算机上的文件夹后,您将拥有一个子文件夹"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>
Run Code Online (Sandbox Code Playgroud)

将此文件复制到assets文件夹并将其包含在项目中.更改文件,您需要将ProductId从"1"更改为"您的产品ID".如果您不需要应用产品中的耗材,则可以删除产品ID ="2"的产品.将第二个许可证信息更改为:

<LicenseInformation>
    <App>
        <IsActive>true</IsActive>
        <IsTrial>false</IsTrial>
    </App>
    <Product ProductId="Your Product ID">
        <IsActive>false</IsActive>
    </Product>
</LicenseInformation>
Run Code Online (Sandbox Code Playgroud)

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

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;            
    }
Run Code Online (Sandbox Code Playgroud)

添加事件处理程序:

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)
    }
}
Run Code Online (Sandbox Code Playgroud)

将这样的内容添加到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
            }
        }            
    }
Run Code Online (Sandbox Code Playgroud)

和参考..

using Windows.Storage;
using Windows.Storage.Streams;
using Windows.ApplicationModel.Store;
using System.ComponentModel;
Run Code Online (Sandbox Code Playgroud)