iOS开发

ios开发 内购教程,ios手机app开发教程视频

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

如对你有帮助,请不要吝惜打赏和喜欢,谢谢!======================第一部分协议===============

CNAPS CODE 查询地址

2016/11/18号更新

没显示的都是可以不填的,主要是打钩 title 和最后面的Self

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

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

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

首先导入StoreKit.framework库

.h文件#import enum{IAP0p20=20,IAP1p100,IAP4p600,IAP9p1000,IAP24p6000,}buyCoinsTag;//代理@interface RechargeVC : UIViewController {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];}// 请求协议//收到的产品信息- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{NSLog(@”———–收到产品反馈信息————–“);NSArray *myProduct = response.products;NSLog(@”产品Product ID:%@”,response.invalidProductIdentifiers);NSLog(@”产品付费数量: %d”, (int)[myProduct count]);// populate UIfor(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]; //支付25break;case IAP1p100:payment = [SKPayment paymentWithProdu

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注