我创建了每月订阅(自动续订),并在App Store Connect中安装了14天的试用版。现在如何激活它?我希望在将用户注册到应用程序中后,立即出现一个窗口,提示您购买每月订阅或利用14天免费版本。如何在代码中使用它?
答案 0 :(得分:1)
您的订阅是否有介绍期都没关系。您需要实现: 1.使用SKProductsRequest获取产品:
func loadProducts(){
let request = SKProductsRequest.init(productIdentifiers: productIds)
request.delegate = self
request.start()
}
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
products = response.products
}
let payment = SKPayment(product: product)
SKPaymentQueue.default().add(payment)
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch (transaction.transactionState) {
case .purchased:
SKPaymentQueue.default().finishTransaction(transaction)
// handle here
break
case .failed:
SKPaymentQueue.default().finishTransaction(transaction)
// handle here
break
case .restored:
SKPaymentQueue.default().finishTransaction(transaction)
// handle here
break
case .deferred, .purchasing:
break
default:
break
}
}
您可以在我的文章中阅读更多详细信息:https://blog.apphud.com/swift-tutorial-subscriptions/
您还可以使用SwiftyStoreKit库。