1

我希望能够确定用户是否曾经订阅过能够更改购买按钮的名称。换句话说,在开始按钮会说,Try It Now如果用户当前订阅按钮会说Subscribed但是如果用户曾经被订阅但订阅已过期我想显示Renew在购买按钮上。

目前一切正常,除了Renew选项。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    Purchases.shared.purchaserInfo { (purchaserInfo, error) in
        self.configurePurchases(purchaserInfo: purchaserInfo)
    }
}

func configurePurchases(purchaserInfo: PurchaserInfo?) {
    if let purchaserInfo = purchaserInfo {
        if purchaserInfo.activeEntitlements.contains("myKillerFeatureEntitlement") {
            myButton.setTitle("Subscribed",for: .normal)
            labelAutoTaxDescription.text = "You are currently subscribed. Thank you for your support."

            let dateFormatter = DateFormatter()
            dateFormatter.dateStyle = .medium
            dateFormatter.timeStyle = .medium

            if let expirationDate = purchaserInfo.expirationDate(forEntitlement: "myKillerFeatureEntitlement") {
                self.labelAutoTaxDetectionPrice.text = "Expiration Date: \(dateFormatter.string(from: expirationDate))"
            }
        }
    }

    // Here is where I need check if it's a returning user so I can change the name of the button
    if isReturningUser{

        myButton.setTitle("Renew",for: .normal)

        // other code
    }
}

检查用户之前是否订阅过的最佳方法是什么?

4

1 回答 1

1

您可以检查对象allPurchasedProductIdentifiers NSSet<NSString *>上的RCPurchaserInfo以查看用户购买的所有产品标识符,无论到期日期如何。

或者,如果您想专门检查“myKillerFeatureEntitlement”权利,您可以检查该purchaseDateForEntitlement属性。如果activeEntitlements为 nil 并且有购买日期,您可以假设它是之前购买的然后过期。

func configurePurchases(purchaserInfo: PurchaserInfo?) {
    if let purchaserInfo = purchaserInfo {
        if purchaserInfo.activeEntitlements.contains("myKillerFeatureEntitlement") {
            myButton.setTitle("Subscribed",for: .normal)
            labelAutoTaxDescription.text = "You are currently subscribed. Thank you for your support."

            let dateFormatter = DateFormatter()
            dateFormatter.dateStyle = .medium
            dateFormatter.timeStyle = .medium

            if let expirationDate = purchaserInfo.expirationDate(forEntitlement: "myKillerFeatureEntitlement") {
                self.labelAutoTaxDetectionPrice.text = "Expiration Date: \(dateFormatter.string(from: expirationDate))"
            }

        // Here is where I need check if it's a returning user so I can change the name of the button
        } else if purchaserInfo.purchaseDate(forEntitlement: "myKillerFeatureEntitlement") != nil {

                myButton.setTitle("Renew",for: .normal)

                // other code
            }
        }
    }
}

请注意,该权利可能已在另一个平台(Android、Web 等)上解锁,因此 iOS 上的按钮实际上可能不会触发恢复。

于 2019-07-03T15:56:34.307 回答