IAP配置过程
第一步:需要配置银行、税务等信息。
第二步:在App Store Connect上配置App的购买项内容。
第三步:代码
第四步:Test,需要使用沙盒测试,App Store Connect上的用户与账号中添加。
中文参考
https://www.jianshu.com/p/7ae9654b85ee
http://nightfade.github.io/2015/08/09/ios-in-app-purchase/
这里还是推荐英文参考:以下是App Store Help上的描述。每一步都很详细了,一些中文的参考都不是很全。
https://help.apple.com/app-store-connect/#/devb57be10e7
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/ShowUI.html#//apple_ref/doc/uid/TP40008267-CH3-SW9
代码流程
第一步:初始化,
// init 的时候注册回调
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
目前是放在了StartUnity方法中。【需要优化】
// dealloc 的时候删除回调
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
第二步:获取Products列表。这个不需要Apple ID登录。这里有两个分支,Debug开发环境和生产环境。目前只要是Debug运行的话,就可以获取到。
第三步:购买。
第四步:Restore已经购买的内容,主要是发生在App重新安装时,目前的方案是通过一个本地持久化的标志位,来判断是否Restore已购买的商品。但如果当前如果没有登录用户的,是否还需要保存AppleID呢?
https://developer.apple.com/documentation/storekit/skpaymentqueue/1506123-restorecompletedtransaction
func restoreCompletedTransactions()
无参数方法,这个是否应该是调用后会弹出UI,选择Apple ID呢?
restoreCompletedTransactions(withApplicationUsername:)
有参数版本,AppUserName 就是AppleID吗?
// 3. 点击恢复购买的时候调用
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
// 4. updatedTransactions中实现 SKPaymentTransactionStateRestored 状态
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
tra