gpt4 book ai didi

ios - IAP(应用内购买)入门价格我如何管理它 iOS?

转载 作者:行者123 更新时间:2023-12-01 18:37:56 25 4
gpt4 key购买 nike

我有一套成功实现IAP introductory price对于 iOS,但我对是否需要在 iOS 端进行任何额外的代码来管理它感到困惑?如果是这样,需要进行哪些更改?

最佳答案

好吧,如果你想正确地实现它,你实际上需要额外的代码。这将给客户带来具体的报价,让他们清楚地了解他得到了什么。

在 iOS 12 和 13 中,您可以获得 3 种不同的订阅介绍价格:

  • 免费试用
  • 随用随付
  • 预付款

  • 关于三者的意义以及订阅的简单和整体 View ,请参阅 Auto-renewable Subscriptions Apple doc with recommended UI

    在向您展示购买 View Controller 时,您应该:
  • 正确显示报价:例如:“ 开始您的 1 个月免费
    试用,然后每月 $1.99
    "免费试用介绍价格;
  • 处理用户已经从过去的介绍价格中受益的事实,因此宁愿显示“ 订阅 1.99 美元/月 ”(到
    继续同一个例子)。这需要您查看用户拥有的收据并检查“is_trial_period”或“is_in_intro_offer_period”是否设置为 true(请参阅我在答案底部的代码)。

  • 在我之前提到的 Apple 文档中,有许多“实际”屏幕显示了不同的用例。

    我的类(class)处理每个产品的介绍价格状态
    /**
    Receipt description
    */
    public class LatestReceipt: CustomStringConvertible {

    public var description: String {
    let prefix = type(of: self)
    return """
    \(prefix) expires \(expiredDate?.compact(timeStyle: .medium) ?? "nil"):
    \(prefix) • product: \(productID);
    \(prefix) • isEligible: \(isEligible);
    \(prefix) • isActive: \(isActive);
    \(prefix) • have been in free trial: \(haveBeenInFreeTrialPeriod);
    \(prefix) • intro date: \(introOfferPeriodDate?.compact(timeStyle: .medium) ?? "nil");
    \(prefix) • free trial period: \(inFreeTrialPeriod).

    """
    }


    /// Related product ID
    var productID = ""


    /**
    Tells whether the user is eligible for any introductory period

    - Note: From the Apple Doc: You can use “is_in_intro_offer_period” value to determine if the user is eligible for introductory pricing. If a previous subscription period in the receipt has the value “true” for either the “is_trial_period” or “is_in_intro_offer_period” keys, the user is not eligible for a free trial or introductory price within that subscription group.
    */
    public var isEligible = true

    /// When did the user benefited the intro offer? Nil means never.
    public var introOfferPeriodDate: Date? = nil
    /// When did the user benefited the free trial? Nil means never.
    public var freeTrialPeriodDate: Date? = nil
    public var inFreeTrialPeriod = false
    /// Tells whether the user benefited the free trial period in the past
    public var haveBeenInFreeTrialPeriod = false
    /// Is still active for today?
    public var isActive = false

    /// Last expired date
    public var expiredDate: Date? = nil

    // Latest receipt content
    public var content = NSDictionary()

    /**
    Replaces the current receipt if the new one is more recent. And compute isActive and others propteries.

    - Parameters:
    - receipt: The new receipt to test.
    */
    public func replaceIfMoreRecent(receipt: NSDictionary) {

    // Replace receipt if more recent
    if let ed = expiredDate {

    // -- Expiring product (aka subscriptions): add only the most recent
    guard let receiptExpiresDate = receipt["expires_date"] as? String,
    let red = StoreKit.getDate(receiptExpiresDate) else {
    print("\(#function): *** Error unable to get receipt expiredDate or convert it to a Date(), skipped")
    return
    }

    // This receipt is most recent than the currently stored? if, yes, replace
    if red.isAfter(ed) {
    content = receipt
    expiredDate = red


    // Is in trial?
    if let tp = content["is_trial_period"] as? String {
    inFreeTrialPeriod = tp == "true"

    if inFreeTrialPeriod {
    haveBeenInFreeTrialPeriod = true
    }
    }

    // When was the intro?
    if let intro = content["is_in_intro_offer_period"] as? String,
    intro == "true" {
    introOfferPeriodDate = red
    }


    let now = Date()

    // Subscription still active today?
    isActive = red.isAfterOrSame(now)

    // Eligibility; check against PREVIOUS subscription period
    if !isActive {
    // You can use “is_in_intro_offer_period” value to determine if the user is eligible for introductory pricing. If a previous subscription period in the receipt has the value “true” for either the “is_trial_period” or “is_in_intro_offer_period” keys, the user is not eligible for a free trial or introductory price within that subscription group.
    let benefitedFromIntroductoryPrice = introOfferPeriodDate != nil || haveBeenInFreeTrialPeriod
    isEligible = !benefitedFromIntroductoryPrice
    }

    }
    print("\(#function): new \(self)")
    }
    }


    init(receipt: NSDictionary) {
    content = receipt

    if let productID = receipt["product_id"] as? String {
    self.productID = productID
    }

    // When subscription, set expires date
    if let receiptExpiresDate = receipt["expires_date"] as? String,
    let red = StoreKit.getDate(receiptExpiresDate) {
    expiredDate = red

    // Is in trial?
    if let tp = content["is_trial_period"] as? String,
    tp == "true" {
    inFreeTrialPeriod = true
    haveBeenInFreeTrialPeriod = true
    }

    // When was the intro?
    if let intro = content["is_in_intro_offer_period"] as? String,
    intro == "true" {
    introOfferPeriodDate = red
    }


    let now = Date()

    // Subscription still active today?
    isActive = red.isAfterOrSame(now)

    // Eligibility; check against PREVIOUS subscription period
    if !isActive {
    // You can use “is_in_intro_offer_period” value to determine if the user is eligible for introductory pricing. If a previous subscription period in the receipt has the value “true” for either the “is_trial_period” or “is_in_intro_offer_period” keys, the user is not eligible for a free trial or introductory price within that subscription group.
    let benefitedFromIntroductoryPrice = introOfferPeriodDate != nil || inFreeTrialPeriod
    isEligible = !benefitedFromIntroductoryPrice
    }
    }
    }

    }

    关于ios - IAP(应用内购买)入门价格我如何管理它 iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48679729/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com