2015年最全的内购图文教程,首先是填各种资料,最后是代码,废话不多说,直接上图

======================第一部分协议===============

第一步

第二步

第三步

第四步

第五步

第六步

第七步

第八步

第九步

第十步

CNAPS CODE 查询地址
https://e.czbank.com/CORPORBANK/query_unionBank_index.jsp

十一步

十二步

十三步

十四步

十五步

十七步

十八步

十九步

二十步
 

=============第二部分创建内购项目============

 

 

 

 

 

 

 
 

===========第三部分贴加内购项目测试账号==========

创建测试账号

沙盒测试员

账号信息
 

=============第四部分主要实现代码==========

首先导入StoreKit.framework

.h文件

#import <StoreKit/StoreKit.h>

enum{
IAP0p20=20,
IAP1p100,
IAP4p600,
IAP9p1000,
IAP24p6000,
}buyCoinsTag; //代理
@interface RechargeVC : UIViewController <SKPaymentTransactionObserver,SKProductsRequestDelegate > {
int buyType;
} - (void) requestProUpgradeProductData; -(void)RequestProductData; -(void)buy:(int)type; - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions; -(void) PurchasedTransaction: (SKPaymentTransaction *)transaction; - (void) completeTransaction: (SKPaymentTransaction *)transaction; - (void) failedTransaction: (SKPaymentTransaction *)transaction; -(void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction *)transaction; -(void) paymentQueue:(SKPaymentQueue *) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError *)error; - (void) restoreTransaction: (SKPaymentTransaction *)transaction; -(void)provideContent:(NSString *)product; -(void)recordTransaction:(NSString *)product; @end

.m文件

#import "RechargeVC.h"

//在内购项目中创的商品单号
#define ProductID_IAP0p20 @"Nada.JPYF01"//20
#define ProductID_IAP1p100 @"Nada.JPYF02" //100
#define ProductID_IAP4p600 @"Nada.JPYF03" //600
#define ProductID_IAP9p1000 @"Nada.JPYF04" //1000
#define ProductID_IAP24p6000 @"Nada.JPYF05" //6000 @interface RechargeVC () @end @implementation RechargeVC - (void)viewDidLoad { [super viewDidLoad]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[self buy:IAP0p20]; } -(void)buy:(int)type
{
buyType = type;
if ([SKPaymentQueue canMakePayments]) {
[self RequestProductData];
NSLog(@"允许程序内付费购买");
}
else
{
NSLog(@"不允许程序内付费购买");
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"您的手机没有打开程序内付费购买"
delegate:nil cancelButtonTitle:NSLocalizedString(@"关闭",nil) otherButtonTitles:nil]; [alerView show]; }
} -(void)RequestProductData
{
NSLog(@"---------请求对应的产品信息------------");
NSArray *product = nil;
switch (buyType) {
case IAP0p20:
product=[[NSArray alloc] initWithObjects:ProductID_IAP0p20,nil];
break;
case IAP1p100:
product=[[NSArray alloc] initWithObjects:ProductID_IAP1p100,nil];
break;
case IAP4p600:
product=[[NSArray alloc] initWithObjects:ProductID_IAP4p600,nil];
break;
case IAP9p1000:
product=[[NSArray alloc] initWithObjects:ProductID_IAP9p1000,nil];
break;
case IAP24p6000:
product=[[NSArray alloc] initWithObjects:ProductID_IAP24p6000,nil];
break; default:
break;
}
NSSet *nsset = [NSSet setWithArray:product];
SKProductsRequest *request=[[SKProductsRequest alloc] initWithProductIdentifiers: nsset];
request.delegate=self;
[request start]; } //<SKProductsRequestDelegate> 请求协议
//收到的产品信息
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{ NSLog(@"-----------收到产品反馈信息--------------");
NSArray *myProduct = response.products;
NSLog(@"产品Product ID:%@",response.invalidProductIdentifiers);
NSLog(@"产品付费数量: %d", (int)[myProduct count]);
// populate UI
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 = nil;
switch (buyType) {
case IAP0p20:
payment = [SKPayment paymentWithProductIdentifier:ProductID_IAP0p20]; //支付25
break;
case IAP1p100:
payment = [SKPayment paymentWithProductIdentifier:ProductID_IAP1p100]; //支付108
break;
case IAP4p600:
payment = [SKPayment paymentWithProductIdentifier:ProductID_IAP4p600]; //支付618
break;
case IAP9p1000:
payment = [SKPayment paymentWithProductIdentifier:ProductID_IAP9p1000]; //支付1048
break;
case IAP24p6000:
payment = [SKPayment paymentWithProductIdentifier:ProductID_IAP24p6000]; //支付5898
break;
default:
break;
}
NSLog(@"---------发送购买请求------------");
[[SKPaymentQueue defaultQueue] addPayment:payment]; }
- (void)requestProUpgradeProductData
{
NSLog(@"------请求升级数据---------");
NSSet *productIdentifiers = [NSSet setWithObject:@"com.productid"];
SKProductsRequest* productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start]; }
//弹出错误信息
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error{
NSLog(@"-------弹出错误信息----------");
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Alert",NULL) message:[error localizedDescription]
delegate:nil cancelButtonTitle:NSLocalizedString(@"Close",nil) otherButtonTitles:nil];
[alerView show]; } -(void) requestDidFinish:(SKRequest *)request
{
NSLog(@"----------反馈信息结束--------------"); } -(void) PurchasedTransaction: (SKPaymentTransaction *)transaction{
NSLog(@"-----PurchasedTransaction----");
NSArray *transactions =[[NSArray alloc] initWithObjects:transaction, nil];
[self paymentQueue:[SKPaymentQueue defaultQueue] updatedTransactions:transactions];
} //<SKPaymentTransactionObserver> 千万不要忘记绑定,代码如下:
//----监听购买结果
//[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions//交易结果
{
NSLog(@"-----paymentQueue--------");
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:{//交易完成
[self completeTransaction:transaction];
NSLog(@"-----交易完成 --------"); UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@""
message:@"购买成功"
delegate:nil cancelButtonTitle:NSLocalizedString(@"关闭",nil) otherButtonTitles:nil]; [alerView show]; } break;
case SKPaymentTransactionStateFailed://交易失败
{ [self failedTransaction:transaction];
NSLog(@"-----交易失败 --------");
UIAlertView *alerView2 = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"购买失败,请重新尝试购买"
delegate:nil cancelButtonTitle:NSLocalizedString(@"关闭",nil) otherButtonTitles:nil]; [alerView2 show]; }break;
case SKPaymentTransactionStateRestored://已经购买过该商品
[self restoreTransaction:transaction];
NSLog(@"-----已经购买过该商品 --------");
case SKPaymentTransactionStatePurchasing: //商品添加进列表
NSLog(@"-----商品添加进列表 --------");
break;
default:
break;
}
}
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction {
NSLog(@"-----completeTransaction--------");
// Your application should implement these two methods.
NSString *product = transaction.payment.productIdentifier;
if ([product length] > 0) { NSArray *tt = [product componentsSeparatedByString:@"."];
NSString *bookid = [tt lastObject];
if ([bookid length] > 0) {
[self recordTransaction:bookid];
[self provideContent:bookid];
}
} // Remove the transaction from the payment queue. [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; } //记录交易
-(void)recordTransaction:(NSString *)product{
NSLog(@"-----记录交易--------");
} //处理下载内容
-(void)provideContent:(NSString *)product{
NSLog(@"-----下载--------");
} - (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{
NSLog(@"-------paymentQueue----");
} #pragma mark connection delegate
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{ } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
switch([(NSHTTPURLResponse *)response statusCode]) {
case 200:
case 206:
break;
case 304:
break;
case 400:
break;
case 404:
break;
case 416:
break;
case 403:
break;
case 401:
case 500:
break;
default:
break;
}
} - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"test");
} -(void)dealloc
{
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];//解除监听 } @end

iOS开发内购全套图文教程的更多相关文章

  1. iOS开发内购图文教程

    2015年最全的内购图文教程,首先是填各种资料,最后是代码,废话不多说,直接上图 ======================第一部分协议=============== 第一步.png 第二步.jpg ...

  2. iOS 开发之内购 – AppStore

    前言本文会给大家详细介绍iOS内购,虽然之前网上也有内购的教程,但是还不够详细,我重新整理出一份教程,希望对大家有所帮助.    基于Xcode7.1.1版本,模拟器iphone6,9.1系统.    ...

  3. iOS开发之内购-AppStore

    本文会给大家详细介绍iOS内购,虽然之前网上也有内购的教程,但是还不够详细,我重新整理出一份教程,希望对大家有所帮助. 基于Xcode7.1.1版本,模拟器iphone6,9.1系统.部分地方直接摘自 ...

  4. 【转】iOS开发Xcode7真机调试教程

    原文网址:https://www.skyfox.org/ios-xcode7-debug-device.html 从Xcode7开始,Xcode 不需要$99/$299升级开发者直接可以进行真机调试 ...

  5. IOS,苹果内购和添加广告

    内购——应用内购买 通过苹果应用程序商店有三种主要赚钱的方式: 直接收费(与国内大部分用户的消费习惯相悖) 广告(降低用户体验 应用程序名称带Lite可以添加广告) O2O -> Online推 ...

  6. 【iOS系列】-iOS查看沙盒文件图文教程(真机+模拟器)

    [iOS系列]-iOS查看沙盒文件图文教程(真机+模拟器) 1:模拟器 1.1 方法1: 程序中打印一下的地址,能直接前往沙盒路径. NSString *path = [NSSearchPathFor ...

  7. iOS APP内购

    看到网上文章一大把,看了这个觉得挺不错的,谢谢 iOS大全 公众平台; 原文:http://mp.weixin.qq.com/s?__biz=MzAxMzE2Mjc2Ng==&mid=2652 ...

  8. iOS 开发-- Runtime 1小时入门教程

    1小时让你知道什么是Objective-C Runtime,并对它有一定的基本了解,可以在开发过程中运用自如. 三.Objective-C Runtime到底是什么东西? 简而言之,Objective ...

  9. Cocos 2d-X Lua 游戏添加苹果内购(一) 图文详解准备流程

    事前准备 最近给游戏添加了苹果的内购,这一块的东西也是刚刚做完,总结一下,其实这里不管是游戏还是我们普通的App添加内购这一块的东西都是差不多的,多出来的部分就是我们Lua和OC的交互的部分,以前刚开 ...

随机推荐

  1. QT官网开源版下载引导(不用登录QT账号)

    一.进入QT官网下载页,首先映入眼前的就是一幅用户选择的调查引导,如下图 二.上图页面显示的可以忽略,直接在上图下载页面上下拉至底部,选择OpenSource->Get started即可进行下 ...

  2. [Selenium] 操作 HTML5 中的 Canvas 绘制图形

    测试 http://literallycanvas.com/ 以 Chrome Driver 为例阐述,通过 Actions 在 Canvas 上绘制一个封闭图形.对于 Canvas 上的操作,推荐 ...

  3. fastText(二):微博短文本下fastText的应用(一)

    众所周知,微博中的内容以短文本居多,文本内容随意性极强,这给建模增加了很大的难度.针对这一问题,这里分享一下fastText在微博短文本的应用. 任务目标简单介绍一下整个任务的目标:给微博内容打上标签 ...

  4. String、StringBuffer和StringBuilder有什么区别?

    1. String 类 String的值是不可变的,这就导致每次对String的操作都会生成新的String对象,不仅效率低下,而且大量浪费有限的内存空间.String a = "a&quo ...

  5. POJ 1737 经典DP

    问题:求含有n个点的连通图的个数. 解: 考虑DP,$f(n)$表示n个点,每个点都和点1相连,且n个点互相连通的图的个数. (蓝字非常重要,这个条件有效地避免了重复计算) $g(n)$表示n个点,每 ...

  6. ios::sync_with_stdio(false);

    取消cin与stdin的同步,加快输入速度

  7. Cardboard对像的公共方法与属性

    一.  public Pose3D EyePose(Eye eye)/// The transformation from head to eye. 获取眼睛在头部坐标系中的局部transform: ...

  8. javascript的回调函数

    函数也是对象 想弄明白回调函数,首先的清楚地明白函数的规则.在javascript中,函数是比较奇怪的,但它确确实实是对象.确切地说,函数是用Function()构造函数创建的Function对象.F ...

  9. 解决Excel打开UTF-8编码CSV文件乱码的问题

    打开 Excel,执行“数据”->“自文本”,选择 CSV 文件,出现文本导入向导,选择“分隔符号”,下一步,勾选“逗号”,去掉“ Tab 键”,下一步,完成,在“导入数据”对话框里,直接点确定 ...

  10. 51nod 1347 【水】

    #include<cstdio> #include <map> #include<iostream> #include<string.h> #inclu ...