c# - Windows 应用商店应用中的应用内购买问题

标签 c# windows windows-runtime windows-phone-8.1 windows-store-apps

我已经创建了一个带有应用内购买的应用程序,并使用 CurrentAppSimulator 对其进行了测试,并且工作正常,但是当我为应用程序创建包时,它失败了

这是我正在为其创建包的代码

public async System.Threading.Tasks.Task InAppInit()
{

    var listing = await CurrentApp.LoadListingInformationAsync();

    // Delux Unlock - Durable
    var unlockFeatureDelux = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "deluxe" && p.Value.ProductType == ProductType.Durable);
    isDeluxPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureDelux.Value.ProductId].IsActive;
    deluxProductID = unlockFeatureDelux.Value.ProductId;

    // Standard Unlock - Durable
    var unlockFeatureStandard = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "standard" && p.Value.ProductType == ProductType.Durable);
    isStarndardPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureStandard.Value.ProductId].IsActive;
    standardProductID = unlockFeatureStandard.Value.ProductId;

}

我在App.xaml.cs中调用此方法OnLaunched

最佳答案

根据我们的讨论,我会这样做:

  • LoadListingInformationAsync 方法使用互联网,如果用户没有互联网连接,则会引发异常。所以我建议将这整个内容包装到 try/ctach block 中
  • 正如我们所见,ProductListings 不包含任何项目。我不知道这个列表是如何填充的,但只要你的应用程序不在商店中,当该列表为空时我就不会感到惊讶(也许有人可以在这里提供帮助......但我没有找到任何与此相关的内容在文档中)。因此,为此,我只需检查您需要的功能是否在列表中...这样您的包将通过您提到的测试,您可以上传它。如果通过商店安装软件包时列表也是空的,则 IAP 设置有问题(但这与商店有关..)
  • 一般性评论:显然此代码并不完整...您需要一些代码来购买 IAP,而这里我们只能获取 Id..(但我认为您只是粘贴了相关部分。)

所有这些都在代码中:

 public async System.Threading.Tasks.Task InAppInit()
    {
        try
        {
            var listing = await CurrentApp.LoadListingInformationAsync();
            if (listing.ProductListings.ContainsKey("deluxe"))
            {
                // Delux Unlock - Durable
                var unlockFeatureDelux = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "deluxe" && p.Value.ProductType == ProductType.Durable);
                isDeluxPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureDelux.Value.ProductId].IsActive;
                deluxProductID = unlockFeatureDelux.Value.ProductId;
            }
            else
            {
                //There is no deluxe IAP defined... so something with your IAP stuff is wrong...
            }

            if (listing.ProductListings.ContainsKey("standard"))
            {
                // Standard Unlock - Durable
                var unlockFeatureStandard = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "standard" && p.Value.ProductType == ProductType.Durable);
                isStarndardPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureStandard.Value.ProductId].IsActive;
                standardProductID = unlockFeatureStandard.Value.ProductId;
            }
            else
            {
                //same as for Delux
            }
        }
        catch
        {
            //Show  this on the UI...
        }
    }

关于c# - Windows 应用商店应用中的应用内购买问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083630/

相关文章:

c# - 我使用 inno setup 来检测是否安装了 .net 4.0 客户端,但效果不佳

c# - 类预设(如 Color.Red)

c# - 在线显示 ValidationResult 错误

windows - 如何编写脚本来修改 Windows 服务器上用户的密码过期值?

c++ - 在两个线程中设置两个鼠标钩子(Hook)

c - EnumWindows 和 CloseHandle

c++ - 使用 Win RT 从相机捕捉快照

C# 将单元写入 In-Sight Explorer (cognex)

memory-management - WinRT是否有垃圾回收?

javascript - 是否可以通过 Javascript 使用推送通知 Windows 8 Metro 应用程序