【问题标题】:UWP apps Release mode CurrentApp errorUWP 应用发布模式 CurrentApp 错误
【发布时间】:2016-01-05 02:37:00
【问题描述】:

我无法在发布模式下运行我的 UWP 应用,因为当我在代码中的某个位置尝试访问 CurrentApp.LicenseInformation 时,它总是会立即崩溃。

重现步骤: 创建一个新的空白 UWP 应用。转到 MainPage.xaml.cs 并添加以下内容:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        Loaded += MainPage_Loaded;
    }

    private void MainPage_Loaded( object sender, RoutedEventArgs e )
    {            
        ProductIapTextBlock.Text = CurrentApp.LicenseInformation.ProductLicenses[ "hello" ].IsActive.ToString();
    }
}

现在更改为发布模式和 x86 平台并尝试运行应用程序。它应该会因上图所示的错误而崩溃。

这里有什么问题?问题是隐藏在我的代码中还是 UWP 中的问题?

【问题讨论】:

  • 见过,但没有帮助。这是一个非常简单和基本的场景,不是 Windows Phone 8.1 应用程序。这就是为什么它是一个更大的问题。
  • 但是您是否检查过您的 Window Store 帐户以查看是否所有内容都已填写?
  • 是的,我做到了。它适用于我从商店获得的任何其他应用程序。

标签: c# uwp


【解决方案1】:

根据本文档:https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.licenseinformation.aspx

应用需要在应用商店中发布,CurrentApp.LicenseInformation 查询才能工作。因此,在开发时,您唯一的选择是使用模拟器版本,然后在准备上传到商店时更改代码。

如果您的代码适用于模拟许可证,请检查它应该在实时商店中工作。但是,我计划将我的应用程序隐藏在商店中(即只能从直接链接获得,不可搜索)以进行测试。然后我会正常发布到商店,如果它有效。

【讨论】:

  • 当我将代码从CurrentAppSimulator 更改为CurrentApp 时,它不仅在我的个人计算机上崩溃,而且在认证过程中也崩溃了。我该如何解决?显然应用程序当时还没有发布,但我也不能使用CurrentAppSimulator,因为获得认证的包最终也会在商店中......
【解决方案2】:

使用compilation directives,在代码的第一行定义指令。

#define DUMMY_STORE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;

namespace SO
{
    public class LicenseManager
    {
        private readonly Dictionary<string, bool> _dummyLicense;

#if DUMMY_STORE
        public LicenseManager()
        {
            // Init license for testing only
            _dummyLicense = new Dictionary<string, bool>
            {
                {"hello", true}
            };
        }
#endif

        public bool IsActive(string feature)
        {
#if DUMMY_STORE
            return _dummyLicense[feature];
#else
            return CurrentApp.LicenseInformation.ProductLicenses[feature].IsActive;
#endif
        }
    }
}

用这个替换你的代码:

private void MainPage_Loaded( object sender, RoutedEventArgs e )
{            
     ProductIapTextBlock.Text = new LicenseManager.IsActive("hello").ToString();
}

并且不要忘记在将其上传到商店之前评论#define DUMMY_STORE

【讨论】:

  • 我知道这可以用于调试,但发布模式在上传到商店之前应该表现良好(至少总是如此)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
  • 2016-07-08
  • 2018-08-14
  • 1970-01-01
  • 2021-06-20
  • 1970-01-01
  • 2020-01-24
相关资源
最近更新 更多