一.向appStore提交资料
![](https://i-blog.csdnimg.cn/blog_migrate/d56076efccb88e96665852c264af8472.webp?x-image-process=image/format,png)
第一步
![](https://i-blog.csdnimg.cn/blog_migrate/6f725d5e900a72f94383ca019a49985c.webp?x-image-process=image/format,png)
第二步
![](https://i-blog.csdnimg.cn/blog_migrate/9472ecd7825aa1b3e4a804bdcedd1bb5.webp?x-image-process=image/format,png)
第三步
操作完第三步然后记得保存
![](https://i-blog.csdnimg.cn/blog_migrate/7f6ccc5dae0d54f4f2e360e347da7f7c.webp?x-image-process=image/format,png)
第四步
![](https://i-blog.csdnimg.cn/blog_migrate/502892b487e0e34df0f5da5c5ae67796.webp?x-image-process=image/format,png)
第五步
先点击Contact Info 的Set Up
![](https://i-blog.csdnimg.cn/blog_migrate/493cf3b2303e7165c35f52298e4b8f7d.webp?x-image-process=image/format,png)
第六步
![](https://i-blog.csdnimg.cn/blog_migrate/5dc9d29ff82b937c105777322c5638e0.webp?x-image-process=image/format,png)
第七步
都填写完记得保存,然后回到上一个页面
![](https://i-blog.csdnimg.cn/blog_migrate/06292469ca9f49f849fb0fff84122bdc.webp?x-image-process=image/format,png)
第八步
![](https://i-blog.csdnimg.cn/blog_migrate/0813cc5ed5c534a0e1a088a47fc71871.webp?x-image-process=image/format,png)
第九步
![](https://i-blog.csdnimg.cn/blog_migrate/4754f4944b5fe6bb94f9bedd78c3b00c.webp?x-image-process=image/format,png)
第十步
![](https://i-blog.csdnimg.cn/blog_migrate/b54e9cbaf91bde8e7ad39e7654efe9cc.webp?x-image-process=image/format,png)
第十一步
![](https://i-blog.csdnimg.cn/blog_migrate/61600eb9d01cf4bb2437420097738d89.webp?x-image-process=image/format,png)
第十二步
进行十二步的时候可能有些银行通过苹果这个方法查不到,就需要借助百度了,一定要准确查询,否则会有问题。我这里推荐一个地址
https://e.czbank.com/CORPORBANK/query_unionBank_index.jsp
![](https://i-blog.csdnimg.cn/blog_migrate/1534cfb808fc66de0d7372cc0b9b97e3.webp?x-image-process=image/format,png)
第十三步
这一步需要注意的是,货币类型可能有歧义,看你是想收美元还是人民币了,都说美元合适。不过,我做的时候为了避免事情,还是选择了CNY,支持国产。还有一点,银行账号如果是对公的账号,需要填写公司的英文名称,如果没有的话,上拼音!然后点击保存银行信息就算ok了,然后退回到最开始的页面
![](https://i-blog.csdnimg.cn/blog_migrate/52e84bb90b50283872444d701b6642c7.webp?x-image-process=image/format,png)
第十四步
![](https://i-blog.csdnimg.cn/blog_migrate/bb3743bbe53b92669ff6fc6e3c43d637.webp?x-image-process=image/format,png)
第十五步
![](https://i-blog.csdnimg.cn/blog_migrate/5397cf03bb9cd852685d349a8b9f8aa5.webp?x-image-process=image/format,png)
第十六步
![](https://i-blog.csdnimg.cn/blog_migrate/2a0956cfd81eeaba3d9a539a6404d557.webp?x-image-process=image/format,png)
第十七步
![](https://i-blog.csdnimg.cn/blog_migrate/347969bbd56f98ed64d80059240366b6.webp?x-image-process=image/format,png)
第十八步
![](https://i-blog.csdnimg.cn/blog_migrate/79f4068d394ccb0cc48266ec6ff5885f.webp?x-image-process=image/format,png)
第十九步
这里要注意的是,虽然这个页面看起来要填写的信息很多,其实很多都没有什么卵用,都是对于美国那边什么法律需要配合的那些,一般咱们都不用,只需要把该勾选的地方勾选,然后提交就好了。
![](https://i-blog.csdnimg.cn/blog_migrate/1b6a12ba65173a8ac5004901b6cbf081.webp?x-image-process=image/format,png)
第二十步
![](https://i-blog.csdnimg.cn/blog_migrate/4bc28d7a007b04cc5a6c113591444e0c.webp?x-image-process=image/format,png)
第二十一步
![](https://i-blog.csdnimg.cn/blog_migrate/d2ed670aefeec700164c8664fee1df2e.webp?x-image-process=image/format,png)
第二十二步
二.创建内购项目
![](https://i-blog.csdnimg.cn/blog_migrate/9696711605a4a7711a785fd9744f9e03.webp?x-image-process=image/format,png)
第一步
![](https://i-blog.csdnimg.cn/blog_migrate/e7ae8f1462f2c86959fe9c690fa6d472.webp?x-image-process=image/format,png)
第二步
根据自己app的需要选择类型,写的很详细,就不多说了
![](https://i-blog.csdnimg.cn/blog_migrate/4092254a072b914ea5b3d7aed2f3ede5.webp?x-image-process=image/format,png)
第三步
![](https://i-blog.csdnimg.cn/blog_migrate/31400fab0737949908ce16651ba013b1.webp?x-image-process=image/format,png)
第四步
![](https://i-blog.csdnimg.cn/blog_migrate/e2a5ce14011f2a9c5ea3aa9f34b24f4e.webp?x-image-process=image/format,png)
第五步
![](https://i-blog.csdnimg.cn/blog_migrate/97dad4eb1bc23d4853fbc5f199291161.webp?x-image-process=image/format,png)
第六步
三、添加项目内购测试帐号
![](https://i-blog.csdnimg.cn/blog_migrate/3caf6fc14a73524d086eaa6c5bc7f73a.webp?x-image-process=image/format,png)
第一步
![](https://i-blog.csdnimg.cn/blog_migrate/85dd71b42ec179e04e3afce9ae754e29.webp?x-image-process=image/format,png)
第二步
四、废话不多说,上代码
第一步导入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
后记
苹果内购还是有不少问题的,还是需要和后台多多配合,例如,购买的时候默认的是当前登录的苹果id付款,如果想切换到别的id就会出现问题。。原来也没有退款流程,现在可以退款了,