移动开发 \ iOS \ iOS苹果内购流程(Apple Pay)

iOS苹果内购流程(Apple Pay)

总点击251
简介:1.登录开发者中心[开发者中心链接](https://developer.apple.com) 2.点击iTunesConnect-->协议、税务和银行业务

1.登录开发者中心[开发者中心链接](https://developer.apple.com)


2.点击iTunes Connect-->协议、税务和银行业务


iOS苹果内购流程(Apple Pay)


3.进入之后我们首先需要申请iOS Paid Application合同,苹果要我们添加一个联系人信息。因为已经做过所以我的界面上并没有这样的提示。盗图一张:


iOS苹果内购流程(Apple Pay)


4.同意协议之后进到这个界面:


iOS苹果内购流程(Apple Pay)


5.这里我们要填写的有:联系人信息(Contact Info)、银行信息(Bank Info)、税务信息(Tax Info)。


iOS苹果内购流程(Apple Pay)


6.进入联系人信息,增加一个联系人信息。


iOS苹果内购流程(Apple Pay)


7.填写银行信息:


(1)选择所在国家


iOS苹果内购流程(Apple Pay)


(2)填写CNAPS Code信息,如果你不清楚的情况下你可以点击Look up CNAPS Code


iOS苹果内购流程(Apple Pay)


(3)查询CNAPS Code并填写


iOS苹果内购流程(Apple Pay)


(4)确认银行卡信息


iOS苹果内购流程(Apple Pay)


(5)填写银行帐号信息,next确认所有信息。


iOS苹果内购流程(Apple Pay)


8.填写税务信息。


(1)税务信息有三个选项:美国税务、澳大利亚税务、加拿大税务。


iOS苹果内购流程(Apple Pay)


(2)这里我们选择美国税务


iOS苹果内购流程(Apple Pay)


(3)这里有两个问题(1)询问你是否是美国居民?(2)询问你有没有美国商业活动?


(4)然后填写你的税务信息,等待审核结果。


9.银行、税收/协议我们就结束了,下边我们就进入到我们的app里去。


iOS苹果内购流程(Apple Pay)


10.选择功能,我们添加一个app内购项目。


iOS苹果内购流程(Apple Pay)


11.添加内购项目


(1)选择类型


iOS苹果内购流程(Apple Pay)


(2)产品名称:是你商品的描述。比如10颗心。产品ID:是一个比较重要的标识,项目通过ID找到商品获取商品信息。价格:可以参考价格表。


iOS苹果内购流程(Apple Pay)


(3)添加语言


iOS苹果内购流程(Apple Pay)


(4)提交一个屏幕快照(按照要求来)。


(5)添加好之后


iOS苹果内购流程(Apple Pay)


12.商品添加好之后我们做最后一步的准备工作--添加沙盒测试帐号。


(1)点击进入用户和职能界面


iOS苹果内购流程(Apple Pay)


(2)选择沙盒技术测试员


iOS苹果内购流程(Apple Pay)


(3)填写测试员信息(必须使用真实的Apple ID 而且这个ID不能被其他开发者添加)


iOS苹果内购流程(Apple Pay)


12.这样我们完成了最后一步的准备工作,下边就是代码实现。为了你们的方便这里我写了一个demo,你们可以下载下来参考一下,当然其中的一些参数需要修改成你们自己的(app内购讲解结束,记得好评哈)。


苹果内购demo地址

转自:http://www.jianshu.com/p/1e6b1152afc6

另附文:http://www.jianshu.com/p/690a7c68664e

iOS内购(iap)

字数945 阅读397 评论4 喜欢4

通过苹果应用程序商店有三种主要赚钱的方式:

1.直接收费(我想天朝的大多数人是不会购买的)


2.广告 iAd Framework


3.内购:应用程序本身的增值产品,(比如什么欢乐豆之类的)


一般式37开,苹果3,开发商7

内购的产品分类:

1>非消耗品(Nonconsumable)一旦购买,终身拥有(终身会员)


2>消费品(Consumable),买了就用,用了就没有了(欢乐豆)


剩下三种不常用:(中国用不上 iBooks)


3>免费订阅


4>自动续费订阅


5>非自动续费订阅

内购流程,苹果官方说明:


iOS苹果内购流程(Apple Pay)


Snip20151006_3.png

iOS苹果内购流程(Apple Pay)


Snip20151006_4.png

添加StoreKit框架,进行内购流程的书写:

#import "ViewController.h"

#import <StoreKit/StoreKit.h>

@interface ViewController () <SKProductsRequestDelegate,SKPaymentTransactionObserver>

/** 所有的产品 */

@property (nonatomic,strong) NSArray *products;

@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

// 通过观察者监听交易状态

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

}

- (void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

}

- (void)viewDidLoad {

[super viewDidLoad];

// 向苹果服务器请求可卖的商品

[self requestProducts];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"恢复" style:UIBarButtonItemStyleDone target:self action:@selector(restore)];

}

/**

* 请求可卖商品

*/

- (void)requestProducts

{

// 1.请求所有的商品

NSString *productFilePath = [[NSBundle mainBundle] pathForResource:@"iapdemo.plist" ofType:nil];

NSArray *products = [NSArray arrayWithContentsOfFile:productFilePath];

// 2.获取所有的productid

NSArray *productIds = [products valueForKeyPath:@"productId"];

// 3.获取productid的set(集合中)

NSSet *set = [NSSet setWithArray:productIds];

// 4.向苹果发送请求,请求可卖商品

SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:set];

request.delegate = self;

[request start];

}

/**

* 当请求到可卖商品的结果会执行该方法

*

* @param response response中存储了可卖商品的结果

*/

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response

{

/*

for (SKProduct *product in response.products) {

NSLog(@"价格:%@",product.price);

NSLog(@"标题:%@",product.localizedTitle);

NSLog(@"秒速:%@",product.localizedDescription);

NSLog(@"productid:%@",product.productIdentifier);

}

*/

// 1.存储所有的数据

self.products = response.products;

self.products = [self.products sortedArrayWithOptions:NSSortConcurrent usingComparator:^NSComparisonResult(SKProduct *obj1,SKProduct *obj2) {

return [obj1.price compare:obj2.price];

}];

// 2.刷新表格

[self.tableView reloadData];

}

#pragma mark - tableView的数据源和代理方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return self.products.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *ID = @"ProductCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

}

// 1.取出模型

SKProduct *product = self.products[indexPath.row];

// 2.给cell设置数据

cell.textLabel.text = product.localizedTitle;

cell.detailTextLabel.text = [NSString stringWithFormat:@"价格:%@",product.price];

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

// 1.取出模型

SKProduct *product = self.products[indexPath.row];

// 2.购买商品

[self buyProduct:product];

}

#pragma mark - 购买商品

- (void)buyProduct:(SKProduct *)product

{

// 1.创建票据

SKPayment *payment = [SKPayment paymentWithProduct:product];

// 2.将票据加入到交易队列中

[[SKPaymentQueue defaultQueue] addPayment:payment];

}

#pragma mark - 实现观察者回调的方法

/**

* 当交易队列中的交易状态发生改变的时候会执行该方法

*

* @param transactions 数组中存放了所有的交易

*/

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

{

/*

SKPaymentTransactionStatePurchasing,正在购买

SKPaymentTransactionStatePurchased,购买完成(销毁交易)

SKPaymentTransactionStateFailed,购买失败(销毁交易)

SKPaymentTransactionStateRestored,恢复购买(销毁交易)

SKPaymentTransactionStateDeferred 最终状态未确定

*/

for (SKPaymentTransaction *transaction in transactions) {

switch (transaction.transactionState) {

case SKPaymentTransactionStatePurchasing:

NSLog(@"用户正在购买");

break;

case SKPaymentTransactionStatePurchased:

NSLog(@"购买成功");

[queue finishTransaction:transaction];

break;

case SKPaymentTransactionStateFailed:

NSLog(@"购买失败");

[queue finishTransaction:transaction];

break;

case SKPaymentTransactionStateRestored:

NSLog(@"恢复购买");

[queue finishTransaction:transaction];

break;

case SKPaymentTransactionStateDeferred:

NSLog(@"最终状态未确定");

break;

default:

break;

}

}

}

// 恢复购买

- (void)restore

{

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

}

广告: 苹果自己搞的内容

1.添加iAd.framework


2.添加ADBannerView视图,并设置代理方法


3.广告条加载完成之前最好隐藏

-

(void)bannerViewDidLoadAd:(ADBannerView

*)banner {

self.bannerBottomConstraint.constant

= 20.0;

[UIView

animateWithDuration:0.5

animations:^{

[self.view

layoutIfNeeded];

}];

NSLog(@"加载广告成功");

}

-

(void)bannerView:(ADBannerView

*)banner didFailToReceiveAdWithError:(NSError

*)error {

NSLog(@"加载广告失败

%@",

error);

}


意见反馈 常见问题 官方微信 返回顶部