IAP(在应用内购买)介绍价格如何管理iOS?

时间:2018-02-08 07:19:29

标签: ios iphone in-app-purchase itunesconnect price

我已经为iOS成功实施了IAP introductory price套装,但我对是否需要iOS端的额外代码进行管理感到困惑?如果是,那么所需的更改是什么?

2 个答案:

答案 0 :(得分:1)

如果您正确实施了IAP入门价格,则不需要在iOS端进行任何额外的工作来管理它。价格通过iTunesConnect界面进行管理。通过正确实现它,我的意思是使用SKProduct API来获取价格并将其显示在应用程序中,这样当您从iTunes连接中更改它时,它也会在应用程序中发生变化。

答案 1 :(得分:0)

好吧,如果您想正确实现它,则实际上需要额外的代码。这样可以为客户提供特定的报价,从而清楚地了解他所得到的。

通过iOS 12和13,您可以获得3种不同的订阅入门价格:

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

要了解这三个方面的重要性以及简单而全面的订阅视图,请参阅Auto-renewable Subscriptions Apple doc with recommended UI

在展示您购买的View Controller时,您应该:

  1. 正确显示报价:例如:“ 免费开始1个月 试用版,然后按月$ 1.99 ”的免费试用价格;
  2. 处理用户过去已经从介绍价中受益的事实,因此显示“ 按月$ 1.99的价格订阅”( 继续相同的示例)。这要求您浏览用户的收据,并检查是否将“ is_trial_period”或“ is_in_intro_offer_period”设置为true(请参阅答案底部的我的代码)。

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

我的课程负责处理每种产品的介绍价格状态

/**
 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
            }
        }
    }

}