如何激活每月订阅的试用订阅(自动续订)?

时间:2019-09-20 09:19:38

标签: ios swift in-app-purchase app-store

我创建了每月订阅(自动续订),并在App Store Connect中安装了14天的试用版。现在如何激活它?我希望在将用户注册到应用程序中后,立即出现一个窗口,提示您购买每月订阅或利用14天免费版本。如何在代码中使用它?

1 个答案:

答案 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
}

  1. 使用SKPaymentQueue启动该产品的付款过程:
let payment = SKPayment(product: product)
SKPaymentQueue.default().add(payment)
  1. 以更新的交易方式处理每个开关案例:
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库。