iOS开发内购图文教程
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(@"失败");
转载于:https://www.cnblogs.com/haohao-developer/p/5613998.html
iOS开发内购图文教程相关推荐
- 直播平台开发时iOS 开发内购功能,直播平台源码搭建
1.首先登录苹果账号,在直播平台源码搭建完成好后,进入后台管理中心添加商品,选择功能----App内购买项目------添加商品类型.商品的ID.以及说明信息. 2.在直播平台源码搭建后台创建沙盒测试 ...
- iOS开发 - 内购沙盒测试正常,因产品返回数为0被苹果审核多次拒绝 (In-app purchase products return 0)
最近给app增加内购移除广告功能,刚开始还比较顺利,把网上找到的内购代码,简单修改加入到app内,基本能用,测试完成后,提交审核.第一次提交,有点问题被拒,根据具体问题进行改正后,再提交,审核就通过了 ...
- iOS开发·内购流程
2019独角兽企业重金招聘Python工程师标准>>> 说明: 涉及到金额交易,苹果审核的一般严格许多.苹果在涉及需要支付中间币的购买必须走苹果内购(例:点券.钻石.K币等等),若是 ...
- iOS开发内购详细版本说明
转自:http://www.jianshu.com/p/c252b2ccb078 一.最近公司很多的项目用到了内购,抽空整理下内购的详细内容吧. 1.先从内购的iTunesConnect里配置说起吧, ...
- iOS开发内购零丢单问题
苹果能够的零丢单操作 文章的主要内容 内购分析 观察者代码构建 着重所以下finishTransaction方法的处理 文章的主要内容 你好!这是我发表的第一段关于苹果技术的博客,如果有说的不对的地方 ...
- iOS开发之内购完全笔记(您已购买此 App 内购买项目。此项目将免费恢复。)
1.内购流程 1.在 AppStore 中创建相应的物品,创建内购沙盒测试账号 2.客户端从后台获取相应的物品 ID (当然也可以再客户端写死,但后期扩展性就受限制了) 3.依据相应的物品 ID 请求 ...
- iOS 开发之内购 – AppStore
来源:Yi'mouleng(@丶伊眸冷) 链接:http://t.cn/R4L0rgA 前言 本文会给大家详细介绍iOS内购,虽然之前网上也有内购的教程,但是还不够详细,我重新整理出一份教程,希望对大 ...
- IOS开发之内购-AppStore
iOS开发之内购-AppStore AppStore 内购 支付 iOS开发 前言 本文会给大家详细介绍iOS内购,虽然之前网上也有内购的教程,但是还不够详细,我重新整理出一份教程,希望对大家有所帮助 ...
- uni app ios 苹果内购
app ios 苹果内购 的步骤 1,准备工作先要uniapp 开发ios 内购需要准备的沙盒 测试账号,在苹果手机登录沙盒账号 也就是把自己的Apple ID退出登录沙盒账号,manifest.js ...
最新文章
- android从放弃到精通 第八天 freedom
- 用python画玫瑰花代码-python绘制玫瑰的实现代码
- 如何准确看清用户需求?
- 力扣914.卡牌分组
- Building Autoencoders in Keras
- mcafee杀死oracle,如何从卸载McAfee卸载工具
- Activity启动过程(一)AMS
- 2018数模国赛A题分析及训练论文
- 什么是云计算,什么是网格计算,两者之间有什么区别?
- 我“药水哥”硬气了 改行‘程序员’了
- 邮件撤回怎么操作?个人邮箱Outlook登录入口在哪?
- 4底2分化查找程序的作业树
- 旋转卡壳算法求最小外接矩形代码
- HashMap的扩容及树化过程
- android studio create device
- C++-------什么是this指针?this指针详解
- 浪潮信息AIStation联合智源研究院 帮助用户灵敏获取本地AI算力
- 让你的LCD1602显示用户自定义字符 Arduino-LiquidCrystal库的createChart()介绍
- [附源码]SSM计算机毕业设计民宿客栈管理系统JAVA
- MySQL数据库安全配置规范