首次从Windows应用商店下载时,如何确定UWP应用的日期和应用版本?

问题描述 投票:1回答:2

我有一个基本的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
2个回答
0
投票

我想让所有将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
}

0
投票

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);
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.