Windows phone 7 Windows Phone授权模块代码是否正确?

Windows phone 7 Windows Phone授权模块代码是否正确?,windows-phone-7,windows-phone-8,in-app-purchase,Windows Phone 7,Windows Phone 8,In App Purchase,我已经编写了使用应用内购买(WP8)和使用市场(WPF和WP8)购买免费试用应用的代码。在提交给市场进行最终测试之前,我只想确定我的代码是否完美 我使用这个方法来验证许可证。iSettings.IsAppPurchased是用于保存或从IsolatedStorageSettings获取值的属性。如果propuct为PUSHARE,则返回true,否则返回false internal static void CheckLicense() { if (iSetting

我已经编写了使用应用内购买(WP8)和使用市场(WPF和WP8)购买免费试用应用的代码。在提交给市场进行最终测试之前,我只想确定我的代码是否完美

我使用这个方法来验证许可证。iSettings.IsAppPurchased是用于保存或从IsolatedStorageSettings获取值的属性。如果propuct为PUSHARE,则返回true,否则返回false

    internal static void CheckLicense()
    {
        if (iSettings.IsAppPurchased)
        {
            return;
        }

        //Check license of Marketplace
        LicenseInformation licInfo = new LicenseInformation();

        //It always return false from device and emulator. 
        if (!licInfo.IsTrial())
        {
            iSettings.IsAppPurchased = true;
            return;
        }
        else
        {
            iSettings.IsAppPurchased = false;
        }


        MyStore.InitializeStore();
        // Return true if target device is WP8 else False
        if (MyStore.IsStoreEnabled)
        {
            //Overload Method
            CheckLicense(MyStore.Store);
        }
    }
这是一种重载方法,用于检查是否使用应用内购买购买了应用的许可证

    internal static void CheckLicense(StoreBase store)
    {
        var productLicenses = store.LicenseInformation.ProductLicenses;

        if (productLicenses != null && productLicenses.Count > 0)
        {
            ProductLicenseBase lic = productLicenses["In_App_Product_ID"];
            if (lic.IsActive)
            {
                iSettings.IsAppPurchased = true;
                store.ReportProductFulfillment(lic.ProductId);
            }
            else
            {
                iSettings.IsAppPurchased = false;
            }
        }
    }
最后一个是使用应用内购买功能购买应用

    internal static void PurchaseIfTrial()
    {
        MyStore.InitializeStore();

        if (!MyStore.IsStoreEnabled)
        {
            MarketplaceDetailTask task = new MarketplaceDetailTask();
            task.ContentType = MarketplaceContentType.Applications;
            task.ContentIdentifier = null;
            task.Show();
        }
        else
        {
            CheckLicense();

            if (!iSettings.IsAppPurchased)
            {
                MyStore.Store.RequestProductPurchaseAsync("In_App_Product_ID", false);
                CheckLicense(MyStore.Store);
            }
        }
    }
我在启动应用程序事件时调用方法CheckLicense

我已经在设备和模拟器上测试了这段代码,但IsTrial()方法总是返回false。是因为测试版

我从这个链接获得了应用内购买代码

如果我做错了什么,请告诉我


谢谢

无法判断您的代码是否“完美”。你可以通过测试来判断它是否正确

只有在从市场安装应用程序后,“IsTrial”功能才能正常运行。
有关测试此功能的建议,请参阅