刚注册的账号来瘟疫公司ios内购账号测试为什么提示是已购买过了呢

10526人阅读
本文会给大家详细介绍iOS内购,这是本人16年5月底的开发过程,希望对看完此篇文章的人有所帮助。
本文基于XcodeVersion 7.3 (7D175)版本,手机是iPhone 6,9.3系统。
部分地方直接摘自网络,基本上是我的逻辑,省时省心省力。
一. 创建测试App
首先你需要登录 App的ItunesConnection,你会看到如下界面
简单的介绍一下这几个选项
1.我的App主要用于管理自己的App应用,例如编辑资料,上架,下架等。
2.销售和趋势主要是来查看App在各个平台的下载量,收入等方面数据,里面有曲线图等图文结合的方式给我们参考。
3.付款和财务报告显示的是你的收入以及付款等相关信息。
4.iAd主要是跟广告有关,开发者可以登录到Workbench,通过iAd对应用的广告进行控制。
5.用户和职能用于生成相应账号,例如苹果沙河测试账号。
6.协议,税务和银行业务则是你银行相关账户的信息设置。
在这里我们选择第一个选项,我的App, 然后点击左上角的加号,新建一个用来测试用的App。
点新建 App,会出现新建窗口;
在这里有几个需要填写的地方,名称自己取,平台IOS,语言选择了简体中文,套装ID也就是你的Bundle Identifier,需要你在 申请BundleID,SKU可以理解为用户看一看到的唯一标示,会体现在你的app的App Store的链接中。
二.添加内购
App创建好之后,我们打开创建的App,在左上角选择功能,会看到左侧的App 内购买项目。我们点击右下角的加号,为App添加内购项目。
之后我们会看到类型的选项,如下图
官方的注释写的很清楚了,只在这里简单的说下前两种:
- 消耗型项目 就像你玩游戏需要买金币,买钻石等,只要花钱就可以无限次的购买
- 非消耗型项目 就像你在App Store购买App,买了一次之后就不用再买第二次,你拥有永久使用权。
在我们的app中,是充值会员,所以选择的是第一种,可以无限次购买。
这里有几个选项,需要填写商品名称,产品ID以及价格等级,简单说明一下
1. 商品名称根据你的消费道具的实际意义来说明,比如“100颗宝石”,“100金币”等。
2. 产品ID是比较重要的,由项目自定义,只要唯一即可,因为测试,我在这里随便填写的123,在实际应用中,一定要认真填写。
3. 价格等级的话“查看价格表”中有对应的说明,可以对照着表中每个国家的货币价格与等级来选择
接下来是语言选择,和上传快照如下图
点击添加语言,填写名称和描述,这里我们依然选择简体中文,如下
审核备注,根据实际情况填写,可以不填。而下面的屏幕快照,则是商品图片,以像素为单位,最低尺寸为321,390,尺寸需求如下图,上传即可。
到这里为止, 我们的内购项目则添加完成。接下来则是测试阶段了。
三.申请沙盒测试账号(用来测试购买项目)
这个账号,是利用苹果的沙盒测试环境来模拟AppStore的购买流程,你肯定不会想要用真实RMB去购买测试吧?
首先我们回到iTunes Connect中,在这里我们选择用户和职能。
然后在上面的第三个选项沙箱技术测试员中点击加号,添加测试员。
在信息填写页面只简单说两句。
所有信息都可以随意填写,不用管是否真实。
App Store地区选择,一定要选对,它对应的是你创建的App的地区, 你App是中国的话, 在这里我们依然选择中国。
此账号只能用来测试,不要在正式的appstore上使用
填写完毕,点击保存后,我们则生成一个测试账号,当然这个账号是可以随时删除和添加的。
之后终于到了写代码的时候了,点开你的Xcode创建你的项目!
大部分代码都可以在.m文件中实现。
#import "ViewController.h"
#import &StoreKit/StoreKit.h&
#import "SVProgressHUD.h"
@interface ViewController ()&SKPaymentTransactionObserver,SKProductsRequestDelegate&
@property (nonatomic,copy) NSString *currentProId;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 100);
button.backgroundColor = [UIColor greenColor];
[button setTitle:@"6元" forState:UIControlStateNormal];
[button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:button];
- (void)btnClick:(UIButton *)button
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
_currentProId = @"123";
if([SKPaymentQueue canMakePayments]){
[self requestProductData:product];
NSLog(@"不允许程序内付费");
- (void)requestProductData:(NSString *)type{
NSLog(@"-------------请求对应的产品信息----------------");
[SVProgressHUD showWithStatus:nil maskType:SVProgressHUDMaskTypeBlack];
NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
NSSet *nsset = [NSSet setWithArray:product];
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
request.delegate = self;
[request start];
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSLog(@"--------------收到产品反馈消息---------------------");
NSArray *product = response.products;
if([product count] == 0){
[SVProgressHUD dismiss];
NSLog(@"--------------没有商品------------------");
NSLog(@"productID:%@", response.invalidProductIdentifiers);
NSLog(@"产品付费数量:%lu",(unsigned long)[product count]);
SKProduct *p = nil;
for (SKProduct *pro in product) {
NSLog(@"%@", [pro description]);
NSLog(@"%@", [pro localizedTitle]);
NSLog(@"%@", [pro localizedDescription]);
NSLog(@"%@", [pro price]);
NSLog(@"%@", [pro productIdentifier]);
if([pro.productIdentifier isEqualToString:_currentProId]){
SKPayment *payment = [SKPayment paymentWithProduct:p];
NSLog(@"发送购买请求");
[[SKPaymentQueue defaultQueue] addPayment:payment];
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error{
[SVProgressHUD showErrorWithStatus:@"支付失败"];
NSLog(@"------------------错误-----------------:%@", error);
- (void)requestDidFinish:(SKRequest *)request{
[SVProgressHUD dismiss];
NSLog(@"------------反馈信息结束-----------------");
#define SANDBOX @"https://sandbox./verifyReceipt"
#define AppStore @"https://buy./verifyReceipt"
-(void)verifyPurchaseWithPaymentTransaction{
NSURL *receiptUrl=[[NSBundle mainBundle] appStoreReceiptURL];
NSData *receiptData=[NSData dataWithContentsOfURL:receiptUrl];
NSString *receiptString=[receiptData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSString *bodyString = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\"}", receiptString];
NSData *bodyData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:SANDBOX];
NSMutableURLRequest *requestM=[NSMutableURLRequest requestWithURL:url];
requestM.HTTPBody=bodyD
requestM.HTTPMethod=@"POST";
NSError *error=nil;
NSData *responseData=[NSURLConnection sendSynchronousRequest:requestM returningResponse:nil error:&error];
if (error) {
NSLog(@"验证购买过程中发生错误,错误信息:%@",error.localizedDescription);
NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@",dic);
if([dic[@"status"] intValue]==0){
NSLog(@"购买成功!");
NSDictionary *dicReceipt= dic[@"receipt"];
NSDictionary *dicInApp=[dicReceipt[@"in_app"] firstObject];
NSString *productIdentifier= dicInApp[@"product_id"];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
if ([productIdentifier isEqualToString:@"123"]) {
int purchasedCount=[defaults integerForKey:productIdentifier];
[[NSUserDefaults standardUserDefaults] setInteger:(purchasedCount+1) forKey:productIdentifier];
[defaults setBool:YES forKey:productIdentifier];
NSLog(@"购买失败,未通过验证!");
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transaction{
for(SKPaymentTransaction *tran in transaction){
switch (tran.transactionState) {
case SKPaymentTransactionStatePurchased:{
NSLog(@"交易完成");
[self verifyPurchaseWithPaymentTransaction];
[[SKPaymentQueue defaultQueue] finishTransaction:tran];
case SKPaymentTransactionStatePurchasing:
NSLog(@"商品添加进列表");
case SKPaymentTransactionStateRestored:{
NSLog(@"已经购买过商品");
[[SKPaymentQueue defaultQueue] finishTransaction:tran];
case SKPaymentTransactionStateFailed:{
NSLog(@"交易失败");
[[SKPaymentQueue defaultQueue] finishTransaction:tran];
[SVProgressHUD showErrorWithStatus:@"购买失败"];
- (void)completeTransaction:(SKPaymentTransaction *)transaction{
NSLog(@"交易结束");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- (void)dealloc{
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
在这里需要注意几点,
1. 代码中的_currentProId所填写的是你的购买项目的的ID,这个和第二步创建的内购的productID要一致;本例中是 123。
2. 在监听购买结果后,一定要调用[[SKPaymentQueue defaultQueue] finishTransaction:tran];来允许你从支付队列中移除交易。
3. 沙盒环境测试appStore内购流程的时候,请使用没越狱的设备。
4. 请务必使用真机来测试,一切以真机为准。
5. 项目的Bundle identifier需要与您申请AppID时填写的bundleID一致,不然会无法请求到商品信息。
6. 真机测试的时候,一定要退出原来的账号,才能用沙盒测试账号
7. 二次验证,请注意区分宏, 测试用沙盒验证,App Store审核的时候也使用的是沙盒购买,所以验证购买凭证的时候需要判断返回Status Code决定是否去沙盒进行二次验证,为了线上用户的使用,验证的顺序肯定是先验证正式环境,此时若返回值为21007,就需要去沙盒二次验证,因为此购买的是在沙盒进行的。
附:苹果支付错误目录
Status Code
Description
The App Store could not read the JSON object you provided.
The data in the receipt-data property was malformed or missing.
The receipt could not be authenticated.
The shared secret you provided does not match the shared secret on file for your account.Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
The receipt server is not currently available.
This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response.Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.
This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:13946次
排名:千里之外
(1)(1)(1)(2)(3)(1)(1)(1)(1)(转)详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程! - 每天记录一点,进步一点 - ITeye技术网站
博客分类:
原创, 欢迎转载,转载请在明显处注明! 谢谢。
原文地址:
终于在11月公司的游戏即将上线了,那么对于iOS游戏来说当今都是内置道具收费属于主流,那么我们的游戏也是内置收费,所以Himi这里分享给大家关于内置应用收费以及申请测试账号进行测试购买的经验;
在应用内嵌入付费代码这一快Himi可以直接将代码分享给大家,所以我们来说一些主要流程,毕竟没有接触过这一块的童鞋肯定相当头疼 =。
OK,步入整体,如果你想在iOS里内嵌收费,那么分为以下几步:
【提示:以下创建App部分内容,你不用非要等项目能打包了才开始做,可以随时并且随便的创建个测试项目即可,因为嵌入付费并不要求上传App的ipa包的!!】
第一步:你需要在iTunesConnect中创建个新的App,然后为这个App设置一些产品(付费道具)等;
OK,这里Himi稍微解释下,iTunesConnect是苹果提供的一个平台,主要提供AP发布和管理App的,最重要的功能是创建管理项目信息,项目付费产品(道具)管理、付费的测试账号、提交App等等,这里就简单介绍这么多,关于产品一词在此我们可以理解成游戏道具即可;在苹果看来所有付费都属于产品 =。 =千万不要纠结字眼哦~
OK,打开iTunesConnect网站: (注意:企业级的用户必须使用公司主开发者账号登陆才可!)
成功登陆后的页面如下:
这里大概说下重要的一些项:
Contracts, Tax, and Banking
: 管理银行账号、联系人以及税等等;这里要根据提示完成对应的信息填写!一定要详细填写喔~
Manage Users :管理用户的,比如主账号以及测试付费的(测试App)账号;
Manage Your Applictions:管理应用程序的,你所有发布的应用和每个应用的状态都在这里面;
下面我们新建一个App项目,大家放心,我们这里创建的是不会直接提交给App审核的,所以放心创建,只要控制好App的状态不要是待审核状态即可,不过即使你不小心将项目提交了,也没事,直接更改App状态即可了;
选择Manage Your Applictions选项,然后新建一个项目:【Add New App】,根据提示来填写吧,这里就不细致说明了~
创建好一个App之后,在点击Manage Your Applictions后的界面应该如下:
这里你将看到自己创建的App,点击你创建的App项目,这里Himi创建的项目名字叫”ProjectForBuyTest“,点击你的App进入如下界面:
(注意:这里的Bundle ID一定要跟你的项目中的info.plist中的Bundle ID保证一致!!!!)
这里可以管理你的项目的信息、状态、是否嵌入GameCenter等等选项,那么本章我们重点介绍如何使用IAp沙盒测试程序内付费,所以这里我们点击右上角的”Manage In-App Purchases“选项进入创建产品(游戏道具)界面如下:
上图中的下方看到Himi创建过的四个产品(道具)了,你可以点击”Create New“选项新建一个产品(付费道具),点击新建如下界面:
上图中Himi没有截图出所有的选项,这里大概介绍下,这个界面是选择你的消费道具的种类,种类说明如下:
类型选择有四种选择:
1.Consumable(消耗品): 每次下载都需要付费;
2.Non-consumable(非消耗品): 仅需付费一次;
3.Auto-Renewable Subscriptions:自动订阅;
4.Free Subscription:免费订阅
最下方是你沙盒测试的截图,暂且不管即可;
这里Himi选择Consumable选项,比如很多游戏都是购买金币啦这样子就可以选择这个;然后出现如下界面:
Reference Name: 付费产品(道具的)参考名称
Product ID(产品ID): 你产品的唯一id。通常格式是 com.xx.yy,但它可以是任何形式,不要求以程序的App ID作为前缀。
Add Language: 添加产品名称与描述语言;
Price Tier:选择价格,这里你选择价格后,会出现如上图最下方的价格对照表
Screenshot(截屏): 展示你产品的截屏。(这个直接无视,测试App务必要管这个的)
Product ID(产品ID)可以创建多个,比如我想游戏中分为0.99$ 、1.99$等道具那就创建对应多个产品ID!
我们填写好了”Reference Name“与”Product ID“以及”Price Tier“后,点击”Add Language“选项然后出现如下界面:
上图中的选项:
Language:语言
Displayed Name(显示名称): 用户看到的产品名称。
Description(描述): 对产品进行描述。
Ok,一路 Save保存回到”Manage In-App Purchases“界面中会看到我们新建的产品(道具)如下:
大家可以看到新建的产品(道具)ID:这里Himi创建的产品ID是com.himi.wahaha ,这里要记住这个产品ID哦~
第二步:申请测试账号,利用沙盒测试模拟AppStore购买道具流程!
回到itunesconnect主页中,选择“Manage Users”然后选择“Test User”,然后出现的界面如下图:
这里Himi已经创建了两个测试账号了,点击界面中的 “Add New User”进行创建即可;记住账号和密码哈,记不住就删掉重新建 娃哈哈~(切记:不能用于真正的AppStore中使用此账号,不仅不能用,而且一旦AppStore发现后果你懂得~)
第三步:在项目中申请购买产品代码以及监听;
这里关于购买的代码部分呢,我都有备注的,Himi这里就不详细讲解了,Himi只是在代码后介绍几点值得注意的地方:
这里Himi是新建的一个Cocos2d的项目,然后给出HelloWorldLayer.h以及HelloWorldLayer.m的全部代码,所有购买代码也全在里面也对应有Himi的注释!
HelloWorldLayer.h
#import "cocos2d.h"
#import &UIKit/UIKit.h&
#import &StoreKit/StoreKit.h&
IAP0p99=10,
}buyCoinsT
@interface HelloWorldLayer : CCLayer&SKProductsRequestDelegate,SKPaymentTransactionObserver&
+(CCScene *)
- (void) requestProUpgradeProductD
-(void)RequestProductD
-(bool)CanMakeP
-(void)buy:(int)
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)
-(void) PurchasedTransaction: (SKPaymentTransaction *)
- (void) completeTransaction: (SKPaymentTransaction *)
- (void) failedTransaction: (SKPaymentTransaction *)
-(void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction *)
-(void) paymentQueue:(SKPaymentQueue *) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError *)
- (void) restoreTransaction: (SKPaymentTransaction *)
-(void)provideContent:(NSString *)
-(void)recordTransaction:(NSString *)
HelloWorldLayer.m
#import "HelloWorldLayer.h"
#define ProductID_IAP0p99 @"com.buytest.one"//$0.99
#define ProductID_IAP1p99 @"com.buytest.two" //$1.99
#define ProductID_IAP4p99 @"com.buytest.three" //$4.99
#define ProductID_IAP9p99 @"com.buytest.four" //$19.99
#define ProductID_IAP24p99 @"com.buytest.five" //$24.99
@implementation HelloWorldLayer
+(CCScene *) scene
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [HelloWorldLayer node];
[scene addChild: layer];
if ((self = [super init])) {
CGSize size = [[CCDirector sharedDirector] winSize];
CCSprite *iap_bg
= [CCSprite spriteWithFile:@"Icon.png"];
[iap_bg setPosition:ccp(size.width/2,size.height/2)];
[self addChild:iap_bg z:0];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[self buy:IAP24p99];
-(void)buy:(int)type
if ([SKPaymentQueue canMakePayments]) {
[self RequestProductData];
CCLOG(@"允许程序内付费购买");
CCLOG(@"不允许程序内付费购买");
UIAlertView *alerView =
[[UIAlertView alloc] initWithTitle:@"Alert"
message:@"You can‘t purchase in app store(Himi说你没允许应用程序内购买)"
delegate:nil cancelButtonTitle:NSLocalizedString(@"Close(关闭)",nil) otherButtonTitles:nil];
[alerView show];
[alerView release];
-(bool)CanMakePay
return [SKPaymentQueue canMakePayments];
-(void)RequestProductData
CCLOG(@"---------请求对应的产品信息------------");
NSArray *product =
switch (buyType) {
case IAP0p99:
product=[[NSArray alloc] initWithObjects:ProductID_IAP0p99,nil];
case IAP1p99:
product=[[NSArray alloc] initWithObjects:ProductID_IAP1p99,nil];
case IAP4p99:
product=[[NSArray alloc] initWithObjects:ProductID_IAP4p99,nil];
case IAP9p99:
product=[[NSArray alloc] initWithObjects:ProductID_IAP9p99,nil];
case IAP24p99:
product=[[NSArray alloc] initWithObjects:ProductID_IAP24p99,nil];
NSSet *nsset = [NSSet setWithArray:product];
SKProductsRequest *request=[[SKProductsRequest alloc] initWithProductIdentifiers: nsset];
request.delegate=
[request start];
[product release];
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSLog(@"-----------收到产品反馈信息--------------");
NSArray *myProduct = response.
NSLog(@"产品Product ID:%@",response.invalidProductIdentifiers);
NSLog(@"产品付费数量: %d", [myProduct count]);
for(SKProduct *product in myProduct){
NSLog(@"product info");
NSLog(@"SKProduct 描述信息%@", [product description]);
NSLog(@"产品标题 %@" , product.localizedTitle);
NSLog(@"产品描述信息: %@" , product.localizedDescription);
NSLog(@"价格: %@" , product.price);
NSLog(@"Product id: %@" , product.productIdentifier);
SKPayment *payment =
switch (buyType) {
case IAP0p99:
= [SKPayment paymentWithProductIdentifier:ProductID_IAP0p99];
case IAP1p99:
= [SKPayment paymentWithProductIdentifier:ProductID_IAP1p99];
case IAP4p99:
= [SKPayment paymentWithProductIdentifier:ProductID_IAP4p99];
case IAP9p99:
= [SKPayment paymentWithProductIdentifier:ProductID_IAP9p99];
case IAP24p99:
= [SKPayment paymentWithProductIdentifier:ProductID_IAP24p99];
CCLOG(@"---------发送购买请求------------");
[[SKPaymentQueue defaultQueue] addPayment:payment];
[request autorelease];
- (void)requestProUpgradeProductData
CCLOG(@"------请求升级数据---------");
NSSet *productIdentifiers = [NSSet setWithObject:@"com.productid"];
SKProductsRequest* productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate =
[productsRequest start];
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error{
CCLOG(@"-------弹出错误信息----------");
UIAlertView *alerView =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Alert",NULL) message:[error localizedDescription]
delegate:nil cancelButtonTitle:NSLocalizedString(@"Close",nil) otherButtonTitles:nil];
[alerView show];
[alerView release];
-(void) requestDidFinish:(SKRequest *)request
NSLog(@"----------反馈信息结束--------------");
-(void) PurchasedTransaction: (SKPaymentTransaction *)transaction{
CCLOG(@"-----PurchasedTransaction----");
NSArray *transactions =[[NSArray alloc] initWithObjects:transaction, nil];
[self paymentQueue:[SKPaymentQueue defaultQueue] updatedTransactions:transactions];
[transactions release];
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
CCLOG(@"-----paymentQueue--------");
for (SKPaymentTransaction *transaction in transactions)
switch (transaction.transactionState)
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
CCLOG(@"-----交易完成 --------");
CCLOG(@"不允许程序内付费购买");
UIAlertView *alerView =
[[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Himi说你购买成功啦~娃哈哈"
delegate:nil cancelButtonTitle:NSLocalizedString(@"Close(关闭)",nil) otherButtonTitles:nil];
[alerView show];
[alerView release];
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
CCLOG(@"-----交易失败 --------");
UIAlertView *alerView2 =
[[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Himi说你购买失败,请重新尝试购买~"
delegate:nil cancelButtonTitle:NSLocalizedString(@"Close(关闭)",nil) otherButtonTitles:nil];
[alerView2 show];
[alerView2 release];
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
CCLOG(@"-----已经购买过该商品 --------");
case SKPaymentTransactionStatePurchasing:
CCLOG(@"-----商品添加进列表 --------");
- (void) completeTransaction: (SKPaymentTransaction *)transaction
CCLOG(@"-----completeTransaction--------");
NSString *product = transaction.payment.productI
if ([product length] & 0) {
NSArray *tt = [product componentsSeparatedByString:@"."];
NSString *bookid = [tt lastObject];
if ([bookid length] & 0) {
[self recordTransaction:bookid];
[self provideContent:bookid];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
-(void)recordTransaction:(NSString *)product{
CCLOG(@"-----记录交易--------");
-(void)provideContent:(NSString *)product{
CCLOG(@"-----下载--------");
- (void) failedTransaction: (SKPaymentTransaction *)transaction{
NSLog(@"失败");
if (transaction.error.code != SKErrorPaymentCancelled)
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
-(void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction *)transaction{
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
NSLog(@" 交易恢复处理");
-(void) paymentQueue:(SKPaymentQueue *) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError *)error{
CCLOG(@"-------paymentQueue----");
#pragma mark connection delegate
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
NSLog(@"%@",
[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
switch([(NSHTTPURLResponse *)response statusCode]) {
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"test");
-(void)dealloc
[super dealloc];
代码注释的相当清楚了,没有什么可解释的,这里说几点值得注意的地方:
1.添加对应对应代码时不要忘记,添加框架 StoreKit.framework,如何添加框架请看我的博文!
2. 越狱机器无法沙盒测试!模拟器的话,Himi用4.3模拟器不可以,因为提示没有开启程序内付费- -(我都没看到模拟器有store的选项,so~);但是使用iOS5的模拟器可以测试沙盒,但是执行的顺序会有些问题,但是还没真机的童鞋可以使用,建议一切以真机实测为准
3. 千万不要忘记在iTunesConnect中创建App Bundle ID一定要跟你的项目中的info.plist中的Bundle ID保证一致!!!!
4. 以上代码中你需要修改的就是我在HelloWorldLayer.m类中的宏定义的Product ID(产品ID),例如Himi刚才新建了一个产品ID是“com.himi.wahaha"
然后我运行项目截图如下以及运行控制台打印的信息如下:
点击Buy之后运行截图以及打印信息:
输入测试账号密码后以及打印信息:
这里Himi最后一张截图是没有购买成功,这里Himi是故意截图出来的,原因就是想告诉童鞋们:
如果你的产品信息能够正常得到,但是始终无法成功的话,不要着急,因为你的产品要进入iTunes Connect,并且Apple准备好沙箱环境需要一些时间。Himi之前遇到过,然后在一天后我没有修改任何一行代码,但产品ID变为有效并能成功购买。=。 =郁闷ing~~
起始要使产品发布到Apple的网络系统是需要一段时间的!
浏览 26860
tank2308635
浏览: 128930 次
来自: 北京
这个版本太老了,admob更新了。我后来尝试[url]http ...
为什么我做出来的ui无法用鼠标操作?滑块拖不动,里面的文字删不 ...
黑苹果系统或者虚拟机的苹果系统怎么安装这个呢?^_^
codeone 写道运行不了,提示BASE SDK MISSI ...
运行不了,提示BASE SDK MISSING

我要回帖

更多关于 ios 内购测试 的文章

 

随机推荐