企业包不支持内购✨✨✨✨✨
- iTunes Store 购买商品
商品类型 (4种):
1. 消耗型
2. 非消耗型
3. 自动续订
4. 非自动续订
- 使用StoreKit库
- 商品模型:
SKProduct :
- 商品id: productIdentifier // com.gy.demoapp.good1
- 商品标题: localizedTitle
- 商品价格: price
- 商品列表展示步骤:
- 向后台获取商品列表
- 去苹果服务端验证商品列表中商品是否可用
/*---SKProductsRequest---*/
//1. 创建请求
self.request = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.request.delegate = self;
[self.request start];
//2. 监听代理 SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response;
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
- 点击购买商品后上传到后台,后台返回订单信息
- 后台返回的订单信息有效,生成订单 SKPayment
//1. 准备付款
SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
payment.applicationUsername = orderId;
weakSelf.price = [weakSelf getProductPrice:product].floatValue;
//2. 加入付款队列,排队付款
[[SKPaymentQueue defaultQueue] addPayment:payment];
//3. 生成交易:SKPaymentTransaction
/*---SKPaymentTransactionObserver---*/
//4. 监听付款队列的交易的状态 ✨✨✨
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions;
//交易状态:
- SKPaymentTransactionStatePurchased 已购买
/*
1. 从交易队列中完成该交易 [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
*/
- SKPaymentTransactionStateFailed 交易失败
/*
1. 判断交易失败的原因,是否是用户取消交易,打印相关日志
2. 从交易队列中完成该交易 [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
*/
- SKPaymentTransactionStateRestored 恢复交易
/*
*/
网友评论