65.9K
CodeProject 正在变化。 阅读更多。
Home

WP7 试用版应用程序重新安装问题

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1投票)

2011年6月20日

CPOL

3分钟阅读

viewsIcon

15505

本文介绍了“应用程序试用期问题(隔离存储)”的一个可能解决方案

引言

本文介绍了一个针对“应用试用期问题(独立存储)”的可能解决方案。

背景

几周前,我开始并成功提交了我的第一个 WP7 应用。我将该应用设置为 5 天的试用期。我让一个朋友下载该应用进行审查。一切正常——甚至在 5 天后出现了“点击购买”。嗯,他没有购买 :-) 而是卸载了它。几天后,我发现了一个错误,我让他再次审查。 “看看这个!!!” 试用期被重置了!

我发现,如果用户卸载应用程序,独立存储也会被删除。所以我开始在谷歌上搜索解决方案。 花了我一整天的时间,但我发现了一些比我需要的更好的东西。

我发现的是:app-license.com 提供了一个基于 Web 服务的 API,用于注册您的应用程序以及试用期到期日期和用户 ID。 现在,如果用户重新安装我的应用程序,我可以调用一个服务来获取初始试用期到期日期。 耶! 太棒了。 但这还不是全部:我给 app-license.com 写了一封电子邮件,因为我需要了解更多信息。 因此,我发现我甚至可以允许我的应用用户通过 PayPal 付款。 这正是我所需要的。 而且费用甚至比使用 Microsoft Marketplace 便宜。 之后,我注册、重建我的应用程序并将其作为免费、非试用应用程序提交到 AppHub,但它没有通过。 Microsoft 无法测试我的应用程序,因为我的试用期为 0 天,他们只能测试“购买”。 下一步是将试用期设置为 3 天,它就通过了! 6 周后,我有足够的下载量并且收到了付款... 从那时起就没有问题了!

Using the Code

使用适用于 WP7 的 app-license.com SDK v1

  1. 首先,在 app-license.com 上注册,转到我的仪表板并注册一个新的应用程序/功能。
  2. 您将在“我的应用”下获得一个 GUID、用户和密码
  3. 下载 SDK 并解压缩。
  4. 向您的主手机项目添加一个引用。
  5. 在 *WMAppManifest.xml* 中添加必要的功能(标识、网络)
  6. 打开 *app.xaml.cs* 并粘贴以下代码
  7. 将应用程序/功能 GUID、alcUser 和 alcPassword 复制到代码中,您就完成了。
#region AppLicense.com
        //App-License.com---------------------------------------------------------------
        /* Note:
         * Add Capabilities in WMAppManifest.xml to
         * Capability Name="ID_CAP_IDENTITY_USER"
         * Capability Name="ID_CAP_NETWORKING"
         */

        static App()
        {
            AppLicenseManager.DebugSettings = 
		new AppLicense.SDK.V1.Sandbox.DebugServiceResonse()
            {
                IsPurchasedAfterCheck = false,
                IsPurchasedInitValue = false,
                IsRegistered = false,
                IsRegisteredAfterServiceRespone = true,
                IsTrialPeriodOver = true
            };
        }

        private AppLicense.SDK.V1.Views.StartView purchaseView = null;
        public AppLicense.SDK.V1.Views.StartView PurchaseView
        {
            get
            {
                if (purchaseView == null)
                    purchaseView = new AppLicense.SDK.V1.Views.StartView();
                return purchaseView;
            }
        }

        private static readonly string appGuid = "Look at myDashboard on App-License.Com";
        private static readonly string alcUser = "Look at myDashboard on App-License.Com";
        private static readonly string alcPassword = "Look at myDashboard on App-License.Com";
        private static readonly int trialInDays = 3; //min

        //Turn to false on LIVE Environment
        //You will not get redirected to a live purchase site
        private static readonly bool useAlcSandbox = true;


        private void alcManager_PropertyChanged
	(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            System.Diagnostics.Debugger.Break();
            //Change values in DebugSettings manually to test next steps
            //AppLicenseManager.DebugSettings.IsPurchasedAfterCheck = true;

            if (e.PropertyName == "IsPurchased" || e.PropertyName == "IsTrialPeriodOver")
            {
                if (AppLicenseManager.Instance.IsPurchased)
                {
                    //Ensure correct view
                    if (RootVisual != RootFrame)
                        this.RootVisual = RootFrame;
                }
                else if (AppLicenseManager.Instance.IsTrialPeriodOver)
                {
                    RootVisual = PurchaseView;
                }
            }
        }
        //App-License.com---------------------------------------------------------------END
        #endregion
private void Application_Launching(object sender, LaunchingEventArgs e)
{
    AppLicenseManager.Instance.Init(appGuid, alcUser, alcPassword, trialInDays, useAlcSandbox);
    //check if previous installed
    AppLicenseManager.Instance.TryUpdateTrialExirationDate();
}

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    AppLicenseManager.Instance.Init(appGuid, alcUser, alcPassword, trialInDays, useAlcSandbox);
    AppLicenseManager.Instance.TryUpdateValuesFromServer();
}
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
    AppLicenseManager.Instance.PropertyChanged += 
	new System.ComponentModel.PropertyChangedEventHandler(alcManager_PropertyChanged);
    if (AppLicenseManager.Instance.IsTrialPeriodOver && 
			!AppLicenseManager.Instance.IsPurchased)
    {
        RootVisual = PurchaseView;
    }
    else if (RootVisual != RootFrame)
    {
        RootVisual = RootFrame;
    }

    // Remove this handler since it is no longer needed
    RootFrame.Navigated -= CompleteInitializePhoneApplication;
}

方法 AppLicenseManager.Instance.TryUpdateTrialExirationDate() 实际上完成了整个工作。 如果您查看源代码,您会发现它尝试获取首次试用期到期日期。 如果该日期不可用,它将注册此功能并存储该日期。 当注册功能的试用期结束后,SDK 会自动引导用户进入购买视图。

测试您的代码

SDK 提供了测试代码的能力。 只要您调试您的代码,您就应该设置

private static readonly bool useAlcSandbox = true; 

然后,您可以根据需要使用 AppLicenseManager.DebugSettings。 您甚至会被重定向到一个沙盒购买站点,您可以在其中模拟真实的购买行为。

关注点

如果您也想使用 app-license... 我做了一个清单来记住

  • 将最短试用期设置为 3 天。
  • 在清单中设置功能(标识、网络)。
  • 确保环境不是沙箱。
  • 仔细检查我的应用程序 guid、用户和密码。
  • 作为免费/非试用应用程序提交。

我的下一个应用程序将包括两个不同的类别,我将尝试分别获得许可。 完成后我会发布。

再想一下:我个人使用此 SDK for WP7,但由于它是基于 Web 服务的,因此应该也可以在所有其他平台上使用它。

历史

  • 2011 年 6 月 20 日:初始发布
© . All rights reserved.