如何在之前确定是否已订阅了用户-Revenuecat



我希望能够确定用户是否曾经订阅过能够更改购买按钮的名称。换句话说,在开始按钮时,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
    }
}

检查用户是否在之前订阅之前是什么?

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

另外,如果要检查" mykillerFeatureEntement" prestrement ,则可以检查purchaseDateForEntitlement属性。如果activeEntitlements是零,并且有一个购买日期,则可以假设它是先前购买的,然后到期。

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上的按钮实际上可能不会触发还原。

最新更新