'In App Purchase

来源:互联网 发布:淘宝hd版登录失败 编辑:程序博客网 时间:2024/05/17 22:28

转自 http://www.cocoachina.com/bbs/read.php?tid-38555.html


In App Purchase的基本流程

1.登陆你的Apple开发者帐号(http://developer.apple.com/iphone
2.创建一个新的Apple ID或是选用一个已存在的Apple ID,点击Config,启用In App Purchase功能。
3.创建develop(用于沙盒测试)和distribution(用于发布)的profile,创建时选择刚才创建的Apple ID。
4.编写你的应用程序(如何在应用程序中实现可以参考in app purchase的官方文档)
5.将你的应用提交到App Store.如果你的应用程序还没有完成只是需要测试,你可以在upload选项卡中选择upload your binary later,或者在提交后self reject你的应用,以免你的应用进入Apple的审核阶段。
6.现在你可以为你的应用程序添加需要购买的东西了,在iTunes Connect中选择Manage Your In App Purchases,然后选择你的应用程序,开始添加你的购买物,Product ID是以后进行purchase操作的唯一识别,相当于主键,而且一旦添加后即使删除了以后也不允许再次使用这一ID(官方建议使用域名的命名模式com.companyname.appname.productid)。Type共有三种选择:Non-Consumable(永久消费) Subscription(订阅) Consumable(可重复购买)。请勾选Cleared for Sale,如果不勾选,在测试时会返回invaild product id。填写好完整的商品信息后如果你的应用程序还未发布需要测试请选择submint with binary,否则请勾选submit now。
7.如果你需要测试你的purchase功能,upload你的应用程序,绑定商品到你的应用程序。
8.安装你的debug版本的应用程序到你的测试机器上进行测试。

In App Purchase的注意点
1.确保你所用来创建Profile的Apple ID启用了In App Purchase功能。
2.确保你的Apple ID的identifier中没有*。
3.确保你的bundle ID和你的Apple ID的identifier一致。
4.确保你的product ID是唯一的。
5.确保你在应用程序中所请求的product ID与你在iTunes Connect里添加的一致。
6.确保你勾选了Clear for Sale。
7.在测试的时候你可能需要等待你的商品添加入Apple的测试沙盒,这个过程可能需要几个小时。
8.在你第一次上传应用程序的时候,确保勾选了需要绑定至该应用程序的商品列表。
9.确保你是在SDK3.0以上编写的。

ECPurchase的使用
ECPurchase是我封装了purchase的内在逻辑,调用简单方便,如果你不想根据文档再自己写purchase功能,那么ECPurchase适合你。


1.在App Delegate中添加Observer
[[ECPurchase shared] addTransactionObserver];

2.设置ECPurchase的product delegate(产品列表代理),transaction delegate(购买结果代理),验证方式
[[ECPurchase shared] setProductDelegate:self];
[[ECPurchase shared] setTransactionDelegate:self];
[[ECPurchase shared] setVerifyRecepitMode:ECVerifyRecepitModeiPhone];

3.请求商品列表
[[ECPurchase shared] requestProductData:identifiers];
实现代理函数绘制UI
-(void)didReceivedProducts:(NSArray *)products;

4.购买商品
[[ECPurchase shared] addPayment:proIdentifier];

5.确认结果
如果不需要收据认证实现代理函数
-(void)didFailedTransaction:(NSString *)proIdentifier;
-(void)didRestoreTransaction:(NSString *)proIdentifier;
-(void)didCompleteTransaction:(NSString *)proIdentifier;
否则实现代理函数
-(void)didCompleteTransactionAndVerifySucceed:(NSString *)proIdentifier;
-(void)didCompleteTransactionAndVerifyFailed:(NSString *)proIdentifier withError:(NSString *)error;
原创粉丝点击