[UWP] [C#]无法从代码隐藏中访问IAP信息 [英] [UWP][C#]Can't access IAPs information from code-behind

查看:86
本文介绍了[UWP] [C#]无法从代码隐藏中访问IAP信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已发布的U​​WP应用程序,我创建了两个加载项,但是当我访问StoreContext对象时,没有任何关于任何加载项的信息。即使我对任何附加组件使用StoreID,我也无法访问任何附加组件的任何信息。


我使用的代码是:

 var currentUser =(等待User.FindAllAsync())。其中(u => u.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated).FirstOrDefault(); 
if(currentUser == null)
{
StoreContextObject = StoreContext.GetDefault();
}
else
{
StoreContextObject = StoreContext.GetForUser(currentUser);
}

var license = await StoreContextObject.GetAppLicenseAsync();
if(!license.IsTrial)
{
AppInfo.Text ="你已经拥有完整的应用程序。没有可供您使用的附加服务。";
返回;
}
var appProductObject = await StoreContextObject.GetStoreProductForCurrentAppAsync();
if(appProductObject!= null)
{
var appProduct = appProductObject.Product;
if(appProduct!= null)
{
AppInfo.Text = $" Title:{appProduct.Title}," +
$" \ nBase Price:{appProduct.Price.FormattedBasePrice}," +
$" \ n当前价格:{appProduct.Price.FormattedPrice}" ;;
AppPurchaseBtn.Visibility = Visibility.Visible;
AppSelfProduct = appProduct;

//显示插件
//获取添加详细信息
SevenDaysAddon = await TrialHelper.GetStoreProductForStoreID(StaticProperties.SevenDaysStreamingBundleID);
ThirtyDaysAddon =等待TrialHelper.GetStoreProductForStoreID(StaticProperties.ThirtyDaysStreamingBundleID);
if(SevenDaysAddon!= null&& ThirtyDaysAddon!= null)
{
if(SevenDaysAddon.IsInUserCollection || ThirtyDaysAddon.IsInUserCollection)
{
AppInfo。 Text = $"您已经购买了一个附加组件。目前还没有进一步的附加收购。请等到加载项过期。";
AddOnPanel.Visibility = Visibility.Collapsed;
AppPurchaseBtn.Visibility = Visibility.Collapsed;
}
else
{
AddOnPanel.Visibility = Visibility.Visible;
}
}
else
{
//不显示任何附加组件
AddOnPanel.Visibility = Visibility.Visible;
AppPurchaseBtn.Visibility = Visibility.Visible;
}
}
}


有人可以帮我解决一下我做错了什么吗?

解决方案

你好Ahmar16,


欢迎来到
开发通用Windows应用论坛
!请使用  标记 
发布到此论坛时,谢谢!


请确保您的应用和附加组件是通过Windows Dev发布的中心仪表板,然后你应该等待1-2天才能使它工作。


祝你好运,


Breeze


I have a published UWP app and there are two add-ons that i have created but when i access the StoreContext object there is no information about any add-ons. Even if i use the StoreID for any add-on i am not able to access any info regarding any add-on.

The code that i am using is:

var currentUser = (await User.FindAllAsync()).Where(u => u.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated).FirstOrDefault();
            if (currentUser == null)
            {
                StoreContextObject = StoreContext.GetDefault();
            }
            else
            {
                StoreContextObject = StoreContext.GetForUser(currentUser);
            }

            var license = await StoreContextObject.GetAppLicenseAsync();
            if (!license.IsTrial)
            {
                AppInfo.Text = "You already own the full app. No add-on acquisition is available for you.";
                return;
            }
            var appProductObject = await StoreContextObject.GetStoreProductForCurrentAppAsync();
            if (appProductObject != null)
            {
                var appProduct = appProductObject.Product;
                if (appProduct != null)
                {
                    AppInfo.Text = $"Title: {appProduct.Title}," +
                        $"\nBase Price: {appProduct.Price.FormattedBasePrice}," +
                        $"\nCurrent Price: {appProduct.Price.FormattedPrice}";
                    AppPurchaseBtn.Visibility = Visibility.Visible;
                    AppSelfProduct = appProduct;

                    //show addons
                    // get add ons details
                    SevenDaysAddon = await TrialHelper.GetStoreProductForStoreID(StaticProperties.SevenDaysStreamingBundleID);
                    ThirtyDaysAddon = await TrialHelper.GetStoreProductForStoreID(StaticProperties.ThirtyDaysStreamingBundleID);
                    if (SevenDaysAddon != null && ThirtyDaysAddon != null)
                    {
                        if (SevenDaysAddon.IsInUserCollection || ThirtyDaysAddon.IsInUserCollection)
                        {
                            AppInfo.Text = $"You have already purchased an add-on. Further add-on acquisition is not yet available. Please wait till the add-on gets expired.";
                            AddOnPanel.Visibility = Visibility.Collapsed;
                            AppPurchaseBtn.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            AddOnPanel.Visibility = Visibility.Visible;
                        }
                    }
                    else
                    {
                        // do not show any add-ons
                        AddOnPanel.Visibility = Visibility.Visible;
                        AppPurchaseBtn.Visibility = Visibility.Visible;
                    }
                }
            }

Can someone help me here as to what i am doing wrong?

解决方案

Hi Ahmar16,

Welcome to the Developing Universal Windows apps forum! Please utilize tagging when posting to this forum, thanks!

Please make sure your app and the add-ons are published through the Windows Dev Center dashboard, then you should wait for 1-2 day to get it work.

Best regards,

Breeze


这篇关于[UWP] [C#]无法从代码隐藏中访问IAP信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆