UWP 应用程序内购
今天来说一下应用程序内购的问题,这里面有坑,给自己做个笔记,也给需要的人提个醒。
我目前的需要是可以允许用户捐赠赞助App的形式内购,最终效果如下
只讲上面的列表部分,下面的就是图片布局啥的,没意思了

应用程序内购,在商店后台叫做“加载项”,你需要按照流程一步一步创建新的加载项即可。。。产品类型我选择的是耐用性(Durable),你也可以选择其他,具体看官方解释

创建好之后,需要提交应用商店审核。

注意!!!坑爹的地方来了

这面即使商店认证通过,你的App也获取不到你创建的加载项!!!【没错,微软经常把你们当爹的,坑的就是你们】
解决办法:
App不是也有一个提交么,要提交一次App更新,并且认证通过,这样才能算是真正的审核通过!!!
=========================华丽丽的分割线=========================
下面开始撸xaml代码了
<ListView Grid.Row="" x:Name="listProducts" IsItemClickEnabled="True" SelectionMode="Single" ItemClick="listProducts_ItemClick">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid BorderBrush="White" BorderThickness="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Image Stretch="UniformToFill" Source="{Binding ProductImage}"/>
<Grid Grid.Column="">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="8*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}" VerticalAlignment="Center"/>
<TextBlock Grid.Column="" FontWeight="Bold" Foreground="Green" Text="{Binding Price}" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
<TextBlock Grid.Row="" TextWrapping="WrapWholeWords" Text="{Binding Description}" VerticalAlignment="Center"/>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
用这个列表来装新建的加载项
然后在用户点击“赞助”按钮的时候相应一个事件,来向应用商店发送请求,下载你的加载项内容。
StoreContext context = null;
public async Task GetAddOnInfo()
{
if (context == null)
{
context = StoreContext.GetDefault();
// If your app is a desktop app that uses the Desktop Bridge, you
// may need additional code to configure the StoreContext object.
// For more info, see https://aka.ms/storecontext-for-desktop.
} // Specify the kinds of add-ons to retrieve.
string[] productKinds = { "Durable" };
List<String> filterList = new List<string>(productKinds); StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(productKinds); if (queryResult.ExtendedError != null)
{
// The user may be offline or there might be some other server failure.
return;
} //后面有代码接着
}
蓝后定义一个Product类
public class Product
{
public string StoreId { get; set; } public string Title { get; set; } public string Description { get; set; } public string Price { get; set; } public string ProductImage { get; set; } }
接上面的代码,根据返回的结果,循环添加在列表的 ItemsSource即可。
foreach (KeyValuePair<string, StoreProduct> item in queryResult.Products)
{
// Access the Store product info for the add-on.
StoreProduct product = item.Value; // Use members of the product object to access listing info for the add-on...
Product pd = new Product()
{
StoreId = product.StoreId,
Title = product.Title,
Price = product.Price.FormattedPrice,
Description = product.Description,
ProductImage = product.Images[].Uri.OriginalString
}; lProducts.Add(pd);
} listProducts.ItemsSource = lProducts;
这样也就完成了加载项的列表显示。

=========================华丽丽的分割线=========================
但是你光显示也不行啊,我要点击,内购哇!!!
所以接着撸代码
private async void listProducts_ItemClick(object sender, ItemClickEventArgs e)
{
StoreContext context = StoreContext.GetDefault();
var product = e.ClickedItem as Product;
var result = await context.RequestPurchaseAsync(product.StoreId);
if (result.Status == StorePurchaseStatus.Succeeded)
{
// 成功购买
textPurchaseResult.Text = "Thank you.";
}
else if (result.Status == StorePurchaseStatus.AlreadyPurchased)
{
// 已经购买过了
textPurchaseResult.Text = "You have already purchased.";
}
else if (result.Status == StorePurchaseStatus.NotPurchased)
{
// 用户没购买,即用户中途取消了操作
textPurchaseResult.Text = "You have canceled the purchase.";
}
else if (result.Status == StorePurchaseStatus.ServerError || result.Status == StorePurchaseStatus.NetworkError)
{
// 发生错误
textPurchaseResult.Text = "Sorry, something went wrong with the microsoft server or something else.";
}
}
OK!!!碎觉!!!
UWP 应用程序内购的更多相关文章
- [Swift通天遁地]四、网络和线程-(15)程序内购功能
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- IAP 程序内购
最近用到IAP内置购买,阅读官方文档,在网上找了些资料,在这里作下整理,以便日后查找和修改,主要流程方向确定,文档和相关转载内容截图不一一指出,google一堆. 1.查找官方文档,两张目录截图,对主 ...
- UWP: 体验应用内购新接口——StoreContext类
Windows 1607 版本(内部版本 14393)之后,微软在 SDK 添加了一些与应用商店相关的新接口,像应用试用与购买.应用内购等.这些接口相对于原来的接口要方便很多.就拿应用内购来说,以前的 ...
- AppStore ipa (苹果内购)笔记
内购示意图 准备条件 苹果的开发者证书,已经为应用启用App内购,并在Xcode更新配置文件 itunes store设置 itunes中创建App及其它设置 参考:iOS应用程序内购/内付费(一) ...
- iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开发汇总
--系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...
- iOS--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook等系统服务开发汇总
iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用系统应用.使用系统服务: ...
- 瘟疫公司中国版(Android)手动破解内购
前言 洒家近日下载了个瘟疫公司中国版(安卓版)(com.easymobi.plagueinc.mi ,版本 1.1.2(5)(.mi 小米版)),发现游戏需要内购而且价格不菲. 需求 root权限 文 ...
- [IPA]IOS In App Purchase(内购)验证
参考我之前的笔记 苹果内购笔记,在客户端向苹果购买成功之后,我们需要进行二次验证. 二次验证 IOS在沙箱环境下购买成功之后,向苹果进行二次验证,确认用户是否购买成功. 当应用向Apple服务器请求购 ...
- ios内购
1.添加框架,storeKit.framework 需要真机调试 /* 内购五步: 1.请求可销售商品的列表 2.展示课销售的商品 3.点击购买 4.开具小票 5.创建交易对象并添加到交易队列 6.创 ...
随机推荐
- Python面向对象篇之元类,附Django Model核心原理
关于元类,我写过一篇,如果你只是了解元类,看下面这一篇就足够了. Python面向对象之类的方法和属性 本篇是深度解剖,如果你觉得元类用不到,呵呵,那是因为你不了解Django. 在Python中有一 ...
- route命令实例练习
第1章 命令配置 虚拟服务器 网卡配置信息 虚拟网卡名称 虚拟网卡模式 服务器01 eth1 10.0.0.10/24 nat模式 服务器02 eth2 10.0.0.11/24 nat模式 eth3 ...
- SQL Server远程连接(2)
- chrome Web开放 字体格式不能显示问题
/** * Chrome 32/33 webfont issue fix. * Requires jQuery. * More info: http://blog.cloudfour.com/chro ...
- Java多线程Master-Worker模式
Java多线程Master-Worker模式,多适用于需要大量重复工作的场景中. 例如:使用Master-Worker计算0到100所有数字的立方的和 1.Master接收到100个任务,每个任务需要 ...
- Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程
Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程Linux版本:Ubuntu 12.04 内核版本:Linux 3.5.0 交叉编译器版本:arm-linux-gcc-4. ...
- 14.javaweb AJAX技术详解
一.简介 1, ajax:在不重新加载网页的前提下,与服务器交换数据并更新部分网页的技巧,但其本身并不是一种新技术 2, 核心:XMLHttpRequest对象.AJAX技术主要是通过此对象完成的 ...
- 关于帧动画steps属性的理解
CSS3的Animation有八个属性 animation-name animation-duration animation-delay animation-iteration-count anim ...
- maven下的sqlserver配置jar包
看了两天的maven,开始把之前做的ssm项目搭建成maven项目,结果在sqlserver的依赖包上受阻,sqlserver需要sqljdbc4.jar包,经过一系列百度教程才得以解决,现在总结一下 ...
- 10个鲜为人知的C#关键字
在正式开始之前,我需要先声明:这些关键字对于偏向底层的程序员更加耳熟能详,对这些关键字不了解并不影响你作为一个合格的程序员. 这意味着这些关键字会让你在编写程序时得到更好的代码质量和可读性,enjoy ...