创建WP8试用应用

参考资料:

创建 Windows Phone 的试用应用

如何在 Windows Phone 应用中实现试用体验

Windows Phone 7 开发 31 日谈——第23日:提供试用版应用程序

 

对资料总结下:

如何检查应用中的试用许可证:

在App.xaml.cs中添加下面两行

using Microsoft.Phone.Marketplace;

private static LicenseInformation _licenseInfo = new LicenseInformation();

使用_licenseInfo.IsTrial()方法,即读取LicenseInformation对象上的IsTrial属性,返回True时为试用版,否则为付费版

但是实际上在调试时,应用的真实许可信息只有在发布到商店后才能使用,所以再在App.xaml.cs里使用以下两段代码。使用后,在调试时将执行#if Debug与#else之间的代码,进行手动设置是否为试用版;在释放模式下时,将执行#else与#endif之间的代码,即读取LicenseInformation对象上的IsTrial属性来设置是否试用版。

        private static bool _isTrial = true;
        public bool IsTrial
        {
            get
            {
                return _isTrial;
            }
        }
        /// <summary>
        /// Check the current license information for this application
        /// </summary>
        private void CheckLicense()
        {
            // When debugging, we want to simulate a trial mode experience. The following conditional allows us to set the _isTrial 
            // property to simulate trial mode being on or off. 
#if DEBUG
            string message = "This sample demonstrates the implementation of a trial mode in an application." +
                               "Press 'OK' to simulate trial mode. Press 'Cancel' to run the application in normal mode.";
            if (MessageBox.Show(message, "Debug Trial",
                 MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                _isTrial = true;
            }
            else
            {
                _isTrial = false;
            }
#else
            _isTrial = _licenseInfo.IsTrial();
#endif
        }

 

在应用开始或恢复时都需要检查应用的许可证:

即在App.xaml.cs中的Application_Launching和Application_Activated事件中添加试用版的判断方法CheckLicense()

 

使用当前应用的许可证信息:

由于在App.xaml.cs里设置了IsTrial属性来读取许可证属性,因此我们可以通过使用(Application.Current as App).IsTrial属性来直接获取应用的许可证信息,避免重复使用IsTrial()方法,该方法一次典型调用耗时60毫秒或更多。

转载于:https://www.cnblogs.com/Scohura/p/4143266.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值