【问题标题】:How to determine the date and app version of a UWP app when it was first downloaded from the Windows Store?如何确定 UWP 应用首次从 Windows 应用商店下载时的日期和应用版本?
【发布时间】:2018-12-28 19:26:32
【问题描述】:

我有一个基本的 Windows 10 UWP 应用:

  • 1.0 版是付费应用
  • 在 2.0 版中,我添加了免费试用版
  • 在 3.0 版中,我想切换到“通过应用内购买免费”。

我希望将所有下载版本 1.0 或 2.0 的现有用户纳入旧功能集,而首次下载 v3.0 的新用户应该看到应用内购买选项。

为此,我需要能够确定每次启动我的应用时最初从 Windows 应用商店购买/下载应用的初始应用版本(或日期),以便我知道要提供哪些功能集。

我发现了Windows.ApplicationModel.Store.CurrentApp,但文档说不应再使用此命名空间。如何判断用户最初购买应用的应用版本?

【问题讨论】:

    标签: uwp windows-10-universal windows-store


    【解决方案1】:

    我希望将所有下载版本 1.0 或 2.0 的现有用户纳入旧功能集,而首次下载 v3.0 的新用户应该看到应用内购买选项。

    目前,没有内置的 API 可供您执行此操作。您必须自己在代码中进行判断。

    例如,您可以使用 LocalSettings 在之前的项目(v1,v2)代码中创建一个标志,如下所示:

    Windows.ApplicationModel.Package package = Package.Current;
    PackageId packageId = package.Id;
    PackageVersion version = packageId.Version;
    if (version.Major < 3)
    {
         ApplicationData.Current.LocalSettings.Values["IsForPreviousVersion"] = true;
    }
    

    然后,您可以为现有用户发布 2.x.x.x 版本到商店,让他们更新已安装的应用程序。一旦他们打开您的应用程序,您的代码就会工作,并且标志将在 LocalSettings 中。 LocalSettings 更新到下一个应用版本时不会被清除。但是,如果用户在更新您的应用时没有打开您的应用,则不会在 LocalSettings 中创建标志。因此,当用户更新到这个 2.x.x.x 版本时,您需要通知他们打开您的应用。

    之后,您可以将您的 v3.0 发布到商店并在您的代码中进行如下判断:

    var IsForPreviousVersion = ApplicationData.Current.LocalSettings.Values["IsForPreviousVersion"];
    if (IsForPreviousVersion != null)
    {
        // is for previous version users
    }
    

    【讨论】:

    • 感谢您的回答。我看到一个潜在的问题:如果用户切换到另一台计算机并尝试在那里下载 v3 怎么办?不会有任何LocalSettings。如果用户重新安装他们的计算机(因此会丢失 LocalSettings),也会出现同样的问题。我可以使用漫游数据,但即使这样也不会无限期地保留......
    • @xavier-xie-msft 您是否考虑向 StoreLicense 添加 API 以确定用户首次获取应用时的原始应用版本?
    • @Mark 您可以在 WPDev UserVoice 上提交“功能请求”。相关团队会考虑的。
    【解决方案2】:

    StoreCollectionData.AcquiredDate Property (Windows.Services.Store) 会告诉您应用程序的获取时间。由于您知道更新的发布时间,因此您可以通过获取日期推断他们购买了哪个版本。

    public static async Task<StoreProductQueryResult> GetAppGameProduct(string ProductId)
    {
        string[] productKinds = { "Application", "Game" };
    
        List<String> filterList = new List<string>(productKinds);
        List<String> idsList = new List<string>();
        idsList.Add(ProductId);
        if (_products == null)
        {
            _products = await _storeContext.GetStoreProductsAsync(filterList, idsList);
        }
        return _products;
    }
    
    private async void Page_Loaded(object sender, RoutedEventArgs e)
    {
        var all = await GetAppGameProduct("<Product Id - See App Identity").ConfigureAwait(true);
        foreach (var product in all.Products)
        {
            IReadOnlyList<StoreSku> skus = (product.Value as StoreProduct).Skus;
    
            for (int i = 0; i < skus.Count; i++)
            {
                Debug.WriteLine(@"{0} {1}", "Title: ", skus[i].Title);
                Debug.WriteLine(@"{0} {1}", "IsTrial: ", skus[i].IsTrial);
                if (skus[i].CollectionData != null)
                {
                    Debug.WriteLine(@"{0} {1}", "CollectionData.AcquiredDate: ", skus[i].CollectionData.AcquiredDate);
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-22
      • 2017-04-03
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 2013-03-30
      • 1970-01-01
      相关资源
      最近更新 更多