none
Windows应用商店应用试用期代码 RRS feed

  • 问题

  • Windows应用商店应用试用期代码,经过几次咨询修改,现调整如下,请各位高明看看是否还有问题?

     protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                TrialModeRefreshScenario();
            }

    private async  void TrialModeRefreshScenario()
            {

                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
               
                if (licenseInformation.IsActive)
                {
                    if (licenseInformation.IsTrial)
                    {
                        var remainingTrialTime = (licenseInformation.ExpirationDate - DateTime.Now).Days;
                        txtblkTryDays.Text = "试用期还剩 " + remainingTrialTime + " 天。";

                        if (remainingTrialTime < 0)      //试用期已过,通知购买
                        {
                            bTryTimeOver = true;          //试用期已过
                            var messageDialog = new MessageDialog("试用期已过,如果要继续使用请购买本软件。", "购买软件");
                                
                            messageDialog.Commands.Add(new UICommand("确定", null, 0));
                            messageDialog.Commands.Add(new UICommand("取消", null, 1));

                            messageDialog.DefaultCommandIndex = 0;
                            var commandChosen = await messageDialog.ShowAsync();
                            switch (commandChosen.Id.ToString())
                            {
                                case "0":
                                    try
                                    {
                                        await CurrentApp.RequestAppPurchaseAsync(false);
                                    }
                                    catch (Exception)
                                    {
                                        Alert("发生购买错误,稍后再试试。", "");
                                    }

                                    //无论购买或取消购买,最后都关闭程序。如果客户购买了,重新打开程序后个别按钮才恢复功能。

                                    App.Current.Exit();
                                    break;
                                case "1":
                                    //点击“取消”,客户没有购买,则关闭程序
                                    App.Current.Exit();
                                    break;
                            }
                        }

                    }
                    else
                    {
                        txtblkTryDays.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    }
                }
                else          //是否试用期过后,客户没有购买时,
                {              //licenseInformation.IsActive就是false?高明解答
                    txtblkTryDays.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    txtblkTryDays.Text = "本程序试用期已过。";
                    bTryTimeOver = true;                                          //试用期已过

                    btnOk.IsEnabled = false;                                      //程序主要按钮无功能

                    var messageDialog = new MessageDialog("试用期已过,如果要继续使用请购买本软件。", "购买软件");
                        
                    messageDialog.Commands.Add(new UICommand("确定", null, 0));
                    messageDialog.Commands.Add(new UICommand("取消", null, 1));

                    messageDialog.DefaultCommandIndex = 0;
                    var commandChosen = await messageDialog.ShowAsync();
                    switch (commandChosen.Id.ToString())
                    {
                        case "0":
                            if (licenseInformation.IsTrial)
                            {
                                try
                                {
                                    await CurrentApp.RequestAppPurchaseAsync(false);
                                    if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                                    {
                                        Alert("您已经购买了本软件。", "");
                                    }
                                    else
                                    {
                                        Alert("您还可以继续试用本软件。", ""); 
                                    }
                                }
                                catch (Exception)
                                {
                                    Alert("发生购买错误,稍后再试试。", "");
                                }
                            }
                            else
                            {
                            }

                            //无论购买或取消购买,最后都关闭程序。如果客户购买了,重新打开程序后个别按钮才恢复功能。

                            App.Current.Exit();
                            break;
                        case "1":
                            //点击“取消”,则关闭程序
                            App.Current.Exit();
                            break;
                    }

                }
            }

    2014年3月23日 2:17

全部回复

  • 建议你可以使用CurrentAppSimulator来做一下测试,如果有问题的话我们乐于帮助。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年3月24日 7:04
    版主
  • 感谢Shi Xin的回复。

    我不知道”检查许可证“的代码放在哪里合适,然后再加载主界面。

    无论放在”MainPage()“ 或 ”OnNavigatedTo()“里,主界面都已经加载了。

    2014年3月26日 9:34